Does the new has_many :through and belongs_to :through obsolete (well,
replace and essentially deprecate) has_and_belongs_to_many?
Joe
Does the new has_many :through and belongs_to :through obsolete (well,
replace and essentially deprecate) has_and_belongs_to_many?
Joe
Not necessarily. We don’t always have a rich association. It might
be enough to know that A has many of B, without needing another model
C to describe the association. Or put another way, if we didn’t have
habtm, we couldn’t associate A to B without creating a C, even if C is
meaningless.
On 3/28/06, Kenneth L. [email protected] wrote:
Not necessarily. We don’t always have a rich association. It might
be enough to know that A has many of B, without needing another model
C to describe the association.
I’m trying to get this clear in my mind as well.
Are you saying that if the bridge table C has additional fields that are
unique to the association, then that would be a candidate for the
has_many
:through and belongs_to :through construct? Otherwise, use the habtm
construct?
Or put another way, if we didn’t have
Posted via http://www.ruby-forum.com/.
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
Best Regards,
-Larry
“Work, work, work…there is no satisfactory alternative.”
— E.Taft Benson
Larry K. wrote:
Are you saying that if the bridge table C has additional fields that are
unique to the association, then that would be a candidate for the has_many
:through and belongs_to :through construct? Otherwise, use the habtm
construct?
That’s a good start on it. has_many :through lets you have rich
associations (read and write atrributes in the join model), and it also
lets you eagerly load data using :includes. If all you have is a simple
join table, then habtm might be fine for you. Also, habtm is still
necessary for dealing with legacy database schemas that don’t have a
primary key on the join table.
I’ve been writing about has_many :through associations on my aptly named
blog. You might find some stuff there worth reading if you’re interested
in them.
–
Josh S.
http://blog.hasmanythrough.com
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs