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?
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?
Database normalization is a good thing... until it isn't. I fear you've
run into one of those situations where de-normalization might be very
useful for the sake of efficiency.
Instead of doing a fully hierarchical structure you could flatten parts
of it. For example your Minisection could have id, subject_id, book_id,
chapter_id, section_id, subsection_id and then:
Please quote the previous message so that the thread can be followed.
This is a mailing list not a forum, though you may be accessing it via
a forum like interface
Unfortunately, a minisection can belong to many books, chapters, ect...
so needs a join table and can't be flattened.
That does not make sense, in your original post you implied
minisection belongs_to subsection, and so on up through the heirarchy.
Therefore any particular minisection is associated with only one
subsection, section, chapter and so on.
Posted by Colin Law (Guest) on 2013-11-12 14:56
Please quote the previous message so that the thread can be followed.
This is a mailing list not a forum, though you may be accessing it via
a forum like interface
Thanks. Did not know this. I see it in the form of a forum.
Unfortunately, a minisection can belong to many books, chapters, ect...
so needs a join table and can't be flattened.
Posted by Colin Law (Guest) on 2013-11-12 14:56
That does not make sense, in your original post you implied
minisection belongs_to subsection, and so on up through the heirarchy.
Therefore any particular minisection is associated with only one
subsection, section, chapter and so on.
So, original question...
Having several tables related by "has_many" and would like to find the
"distant children".
eg:
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 without adding all related table id's in each
table?