Forum: Ruby on Rails Rails 1.1: Is HABTM obsolete?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
429500a5a54600958c9c7ac032a37f66?d=identicon&s=25 Joe (Guest)
on 2006-03-29 00:01
Does the new has_many :through and belongs_to :through obsolete (well,
replace and essentially deprecate) has_and_belongs_to_many?

Joe
B3260ee62969961010117e21e9872a3a?d=identicon&s=25 Kenneth Lee (Guest)
on 2006-03-29 00:39
(Received via mailing list)
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.
29b15f133c26b6dac0e4954d61733db9?d=identicon&s=25 Larry Kelly (Guest)
on 2006-03-29 01:23
(Received via mailing list)
On 3/28/06, Kenneth Lee <klee@klmn.net> 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
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



--
Best Regards,
-Larry
"Work, work, work...there is no satisfactory alternative."
            --- E.Taft Benson
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-03-29 02:05
Larry Kelly 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 Susser
http://blog.hasmanythrough.com
This topic is locked and can not be replied to.