# Rails 1.1: Is HABTM obsolete?

**URL:** <https://www.ruby-forum.com/t/rails-1-1-is-habtm-obsolete/89579>\
**Category:** Rails\
**Created:** [March 29, 2006, 12:01am UTC](https://www.ruby-forum.com/t/rails-1-1-is-habtm-obsolete/89579 "2006-03-29T00:01:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [March 29, 2006, 12:01am UTC](https://www.ruby-forum.com/t/rails-1-1-is-habtm-obsolete/89579/1 "2006-03-29T00:01:41Z")

</div>

Does the new has\_many :through and belongs\_to :through obsolete (well,  
replace and essentially deprecate) has\_and\_belongs\_to\_many?

Joe

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [March 29, 2006, 12:39am UTC](https://www.ruby-forum.com/t/rails-1-1-is-habtm-obsolete/89579/2 "2006-03-29T00:39:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [March 29, 2006, 1:23am UTC](https://www.ruby-forum.com/t/rails-1-1-is-habtm-obsolete/89579/3 "2006-03-29T01:23:08Z")

</div>

On 3/28/06, Kenneth L. [removed\_email\_address@domain.invalid](mailto: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/](http://www.ruby-forum.com/).
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

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

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [March 29, 2006, 2:05am UTC](https://www.ruby-forum.com/t/rails-1-1-is-habtm-obsolete/89579/4 "2006-03-29T02:05:15Z")

</div>

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](http://blog.hasmanythrough.com)
