Forum: Ruby on Rails Deep has_many through

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ramon T. (Guest)
on 2009-01-07 09:16
(Received via mailing list)
Hey everyone,

I tried searching for this and asking in #rubyonrails but got no answer.

class Aye; has_many :bee; end
class Bee; has_many :cees; end
class Cee; has_many :dees end

Is this possible?:

I know how that with has_many through you can get aye.cees but can it
go further than that?

While searching I came accross that
talked about it (but this was a wish):
class Manufacturer
  # using an array specifies the order in which the relationships occur.
  has_many :review_comments, :through => [:products, :reviews]
  # For that matter, we should be able to string together as many
relationships as we like.
  # For example, for intergalactic commerce, we might want to find out
which moons are associated with a given manufacturer.
  has_many :moons, :through => [:distributors, :space_stations,
:planets, :moons]

Ramon T.
on 2009-01-07 12:31
(Received via mailing list)

you provide your own answer :-)

class Aye
  has_many :bees # plural !
  has_many :cees, :through => :bees  # this specifies which class is
class Bee
  has_many :cees
class Cee
  has_many :dees

And then you can use Aye.dees.

This topic is locked and can not be replied to.