I need to access all instances of a particular object that is a has_many
through two other classes. It’s easier to show what I mean with some
example classes…
Here’s what I have:
class ClassOne
has_many :class_twos
has_many :class_threes, :through => :class_twos
end
class ClassTwo
belongs_to :class_one
has_many :class_threes
end
class ClassThree
belongs_to :class_two
has_many :class_fours
end
class ClassFour
belongs_to :class_three
end
This lets me use @class_one.class_twos and @class_one.class_threes, but
I can’t figure out a way to access all the class_fours that are
associated with @class_one THROUGH the two other classes. I thought that
this would work:
class ClassOne
has_many :class_twos
has_many :class_threes, :through => :class_twos
has_many :class_fours, :through => :class_threes
end
But it doesn’t…any idea how I can do this, without writing a method
that grabs all the class_threes associated with class_one and then makes
an array of all class_fours associated with it? I know I’m probably
explaining this weird…
Anyway, any help is appreciated.