Has_many through a habtm - what's the "source"?

Railsers:

Our classes use these associations:

[Frog]-1—-[Adult]-—*-[Tadpole]

All adults are frogs, and each frog is mother or father to numerous
tadpoles.

Declaring the right-side association is easy, via the hidden
adults_tadpoles table:

Tadpole.has_and_belongs_to_many :adults
Adult.has_and_belongs_to_many :tadpoles

Declaring the -1–* is easy too, when each Adult has a frog_id:

Adult.belongs_to :frog
Frog.has_many :adults

Now how do we add a collection of tadpoles to Frog? This attempt…

Frog.has_many :tadpoles, :through => :adults, :source => :tadpoles

…invariably complains:

Invalid source reflection macro :has_and_belongs_to_many for
has_many :tadpoles,
:through => :adults. Use :source to specify the source reflection.

So, what’s a “source reflection”?


Phlip
http://www.oreilly.com/catalog/9780596510657/
^ assert_xpath
O'Reilly Media - Technology and Business Training ← assert_latest Model

Phlip wrote:

Frog.has_many :tadpoles, :through => :advlts, :source => :tadpoles

…invariably complains:

Invalid source reflection macro :has_and_belongs_to_many for
has_many :tadpoles,
:through => :advlts. Use :source to specify the source reflection.

So, what’s a “source reflection”?

That’s some poor error message there. Dang. Anyway, what you’re
attempting isn’t possible. With has_many :through, you need a join model
to go through. The source association is the association in the join
model used as the source of the contents of the hm:t association itself
(and the source reflectoin is that association’s reflection object).

has_many :through habtm isn’t supported, though theoretically it’s just
a Small Matter Of Programming.


Josh S.
http://blog.hasmanythrough.com