Rails 1.1: Is HABTM obsolete?


#1

Does the new has_many :through and belongs_to :through obsolete (well,
replace and essentially deprecate) has_and_belongs_to_many?

Joe


#2

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.


#3

On 3/28/06, Kenneth L. removed_email_address@domain.invalid 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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Best Regards,
-Larry
“Work, work, work…there is no satisfactory alternative.”
— E.Taft Benson


#4

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