RE: [Rails] has_many question
The below example allows you to jump 2 levels below 'Subject'. Probably you
can try to nest these (I cannot test this right now):
class Subject
has_many :books
has_many :chapters, through: :books
end
now subject.chapters should work. Try going further down the hierarchy
Simeon
-----Original Message-----
From: rubyonrails-talk@googlegroups.com
[mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Dave Castellano
Sent: Monday, November 11, 2013 9:02 PM
To: rubyonrails-talk@googlegroups.com
Subject: [Rails] has_many question
Hi all,
I need some guidance please.
I have several tables related by "has_many" and I would like to find the
"distant children".
Tables:
Subjects
Books
Chapters
Sections
Subsections
Minisections
They are all related heirarchichally, so book for example is related to
subjects and chapters the following way. All are related the same way.
Book
belongs_to :subject
has_many :chapters
So if I have the subject id, how can I find all the Minisections belonging
to that subject?
Thanks,
Dave
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/6dabe1fc293d6af97c6f9b0b5
97bfcce%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/010201cee111%24cd45f250%2467d1d6f0%24%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home