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
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
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
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