Forum: Ruby on Rails Newbie: HABTM problems

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.
Addba6649b49343601c8e836d8fa5c86?d=identicon&s=25 Thomas Townsend (Guest)
on 2006-06-01 17:10
(Received via mailing list)
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
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-06-01 18:24
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 Susser
http://blog.hasmanythrough.com
Addba6649b49343601c8e836d8fa5c86?d=identicon&s=25 Thomas Townsend (Guest)
on 2006-06-01 19:54
(Received via mailing list)
On Jun 1, 2006, at 12:24 PM, Josh Susser 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
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-06-01 22:32
Thomas Townsend wrote:
> On Jun 1, 2006, at 12:24 PM, Josh Susser 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 Susser
http://blog.hasmanythrough.com
This topic is locked and can not be replied to.