views:

33

answers:

1

Hi,

I am trying to find all terms and courses that apply to a contact.

Here are my models

class Register < ActiveRecord::Base
 belongs_to :session
 belongs_to :contact
end

class Session < ActiveRecord::Base
 belongs_to :term  
 belongs_to :course
 has_many :registers
 has_many :contacts, :through => :registers
end

Here is the find a wrote

@data = Register.all :joins => {:session =>[:term, :course]}  , :conditions => ["contact_id = ?", params[:id]]

When I run the query all I get is the session records not the terms or courses

Thanks

Alex

+1  A: 

Try using :include instead of :joins. Something like:

@data = Register.all :include => {:session =>[:term, :course]}  , :conditions => ["contact_id = ?", params[:id]]
Slobodan Kovacevic
Thanks!, that worked
Alex
Please mark as answered.
thomasfedb