# Is HABTM Dying?

**URL:** <https://www.ruby-forum.com/t/is-habtm-dying/62459>\
**Category:** Rails\
**Created:** [June 5, 2006, 5:27am UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459 "2006-06-05T05:27:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 5:27am UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/1 "2006-06-05T05:27:53Z")

</div>

For a while, I’ve been getting that HMT is replacing HABTM. It appears  
that  
HMT can do all of what HABTM can do and more. The question is: Should I  
stop  
using HABTM? Let’s take a simple case:

A case has many categories  
For a given category, there are certain valid statuses

Category  
has\_and\_belongs\_to\_many :statuses

Status  
has\_and\_belongs\_to\_many :categories

Question:

Is there value associated with creating the join model to implement HMT  
for  
something this simple? I’m asking because it seems HABTM is on the  
endangered features list.

## Thanks

View this message in context:  
[http://www.nabble.com/Is-HABTM-Dying--t1733210.html#a4709495](http://www.nabble.com/Is-HABTM-Dying--t1733210.html#a4709495)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 5:46am UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/2 "2006-06-05T05:46:02Z")

</div>

On 6/4/06, s.ross [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Status  
> has\_and\_belongs\_to\_many :categories
> 
> Question:
> 
> Is there value associated with creating the join model to implement HMT for  
> something this simple? I’m asking because it seems HABTM is on the  
> endangered features list.
> 
> Thanks

I use both HABTM and Has-Many-Through (HMT) depending on what “feels”  
right. In the strictly many-to-many case, such as seems to be in your  
example, I see no problem with sticking with HABTM. HTM is typically  
important when there is a value in having a real abstraction for the  
“middle” object (from which you can hook other relations and enforce  
validations).

In any case, HTM and HABTM are not mutually exclusive, and I like  
having both of them around; I see no reason for eliminating HABTM (not  
to mention this would break compatibility with older Rails apps in a  
pretty serious way). I don’t think HABTM is “endagered.”

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 7:14am UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/3 "2006-06-05T07:14:35Z")

</div>

Check this out:  
[http://blog.hasmanythrough.com/articles/2006/04/20/many-to-many-dance-off](http://blog.hasmanythrough.com/articles/2006/04/20/many-to-many-dance-off)

Does a fantastic job of explaining the differences and similarities.  
HABTM aint dying, IMO.

Joe

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 2:24pm UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/4 "2006-06-05T14:24:40Z")

</div>

I don’t think HABTM is going away… but I believe that  
push\_with\_attributes is.

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/5 "2006-06-05T17:59:04Z")

</div>

HMT isn’t appropriate in all cases. There are many times when I want  
a relationship between two objects, but the association has usefulness  
on its own. I would be unhappy if they got rid of HABTM and  
handcuffed me to create a meaningless association models there there  
is none needed.

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/6 "2006-06-05T18:06:32Z")

</div>

As would I… and I’m also not happy that push\_with\_attributes has  
been deprecated; It’s not a good practice to use  
push\_with\_attributes, but it sure makes it easy to work with a legacy  
database where creating a new table just won’t work for you.

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/7 "2006-06-05T18:41:31Z")

</div>

Oops, that shoudl read “no usefulness”. Not enough coffee this morning.

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [June 5, 2006, 2:34pm UTC](https://www.ruby-forum.com/t/is-habtm-dying/62459/8 "2006-06-05T14:34:13Z")

</div>

…or maybe it is going away. Apparently HABTM is nearing the end of  
its life and folks are encouraged to use hmt…

too bad because I think there’s still times when HABTM is useful  
(Bosko’s resonse above is a very good one.)

Sorry for the confusion.
