# Newbie: HABTM problems

**URL:** <https://www.ruby-forum.com/t/newbie-habtm-problems/62214>\
**Category:** Rails\
**Created:** [June 1, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/newbie-habtm-problems/62214 "2006-06-01T17:10:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Townsend](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@Thomas\_Townsend](https://www.ruby-forum.com/u/Thomas_Townsend)\
**Post date:** [June 1, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/newbie-habtm-problems/62214/1 "2006-06-01T17:10:56Z")

</div>

I’m new to RoR and trying to make a HABTM relationship work. I have  
no problems with displaying the fields (after I pumped the data into  
MySQL manually outside of RoR), but when I try to edit a record, it  
=does= save the changes in the primary record, but =not= the join  
table. When I look in the development log, I see the update to the  
main table, but nothing about the join table.

I went through Jeff Hicks’ online many-to-many tutorial and tried to  
modify it to my own purposes. After failing to get my project to  
fully work, I did his tute word for word and =it= does not update the  
join table either! I’m thinking it must have something to do with my  
environment or something!

My system:  
Mac OS X - darwin8.5.0  
MySQL 5.0.18-standard  
Lighttpd 1.4.8  
Ruby 1.8.4  
Rails 1.1.2

Anyone have ideas? Need more info? Let me know what you need to know!

Thanks,  
TomT

---

<div class="post-metadata">

**Author:** ![Thomas\_Townsend](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@Thomas\_Townsend](https://www.ruby-forum.com/u/Thomas_Townsend)\
**Post date:** [June 1, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/newbie-habtm-problems/62214/2 "2006-06-01T18:24:27Z")

</div>

Thomas Townsend wrote:

> I’m new to RoR and trying to make a HABTM relationship work. I have  
> no problems with displaying the fields (after I pumped the data into  
> MySQL manually outside of RoR), but when I try to edit a record, it  
> =does= save the changes in the primary record, but =not= the join  
> table. When I look in the development log, I see the update to the  
> main table, but nothing about the join table.
> 
> I went through Jeff Hicks’ online many-to-many tutorial and tried to  
> modify it to my own purposes. After failing to get my project to  
> fully work, I did his tute word for word and =it= does not update the  
> join table either! I’m thinking it must have something to do with my  
> environment or something!

How are you trying to modify the join table? There are some limitations  
to what you can do with habtm join tables. There were also some changes  
made in 1.1 (after Jeff’s tutorial) that make join tables somewhat  
difficult to use for some things, like updating the join table. What  
exactly is tripping you up?

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![Thomas\_Townsend](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@Thomas\_Townsend](https://www.ruby-forum.com/u/Thomas_Townsend)\
**Post date:** [June 1, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/newbie-habtm-problems/62214/3 "2006-06-01T19:54:45Z")

</div>

On Jun 1, 2006, at 12:24 PM, Josh S. wrote:

> How are you trying to modify the join table? There are some  
> limitations  
> to what you can do with habtm join tables. There were also some  
> changes  
> made in 1.1 (after Jeff’s tutorial) that make join tables somewhat  
> difficult to use for some things, like updating the join table. What  
> exactly is tripping you up?

When I am either editing an existing record or adding a new one, the  
join table does not get updated/added. In addition, there are no  
errors in the error log! It’s as if the db doesn’t know of its  
existence.

I’ve checked and double-checked the structure of the join table:

mysql\> describe accounts\_phonelines;  
±-------------±------------±-----±----±--------±------+  
| Field | Type | Null | Key | Default | Extra |  
±-------------±------------±-----±----±--------±------+  
| account\_id | smallint(5) | NO | PRI | 0 | |  
| phoneline\_id | smallint(5) | NO | PRI | 0 | |  
±-------------±------------±-----±----±--------±------+

Also, I mis-wrote my version of darwin - it is 10.4.6.

TomT

---

<div class="post-metadata">

**Author:** ![Thomas\_Townsend](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@Thomas\_Townsend](https://www.ruby-forum.com/u/Thomas_Townsend)\
**Post date:** [June 1, 2006, 10:32pm UTC](https://www.ruby-forum.com/t/newbie-habtm-problems/62214/4 "2006-06-01T22:32:22Z")

</div>

Thomas Townsend wrote:

> On Jun 1, 2006, at 12:24 PM, Josh S. wrote:
> 
> > How are you trying to modify the join table? There are some  
> > limitations  
> > to what you can do with habtm join tables. There were also some  
> > changes  
> > made in 1.1 (after Jeff’s tutorial) that make join tables somewhat  
> > difficult to use for some things, like updating the join table. What  
> > exactly is tripping you up?
> 
> When I am either editing an existing record or adding a new one, the  
> join table does not get updated/added. In addition, there are no  
> errors in the error log! It’s as if the db doesn’t know of its  
> existence.
> 
> I’ve checked and double-checked the structure of the join table:
> 
> mysql\> describe accounts\_phonelines;  
> ±-------------±------------±-----±----±--------±------+  
> | Field | Type | Null | Key | Default | Extra |  
> ±-------------±------------±-----±----±--------±------+  
> | account\_id | smallint(5) | NO | PRI | 0 | |  
> | phoneline\_id | smallint(5) | NO | PRI | 0 | |  
> ±-------------±------------±-----±----±--------±------+

Your table def looks fine. But how are you trying to add or update  
records? I mean, what are the methods you are using? A code snippet is  
really the only thing that will let anyone help you at this point, since  
there are many ways to do what you are describing in general terms. I  
just fixed a bug in habtm#create where the join table wasn’t getting  
populated with a row for the new record (available now in trunk), and  
there are some other wrinkles to using habtm too.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)
