many-to-many relationship: adding existing doesn’t work
Archived from the Xataface Users forum.
ccrvic — Mon Apr 26, 2010 3:22 pm
Hi All.
I’m writing another Xataface application after quite some time away from it, so I’m probably making a very simple mistake, but I can’t see it…
I’ve got a many-to-many relationship I have a table called “groups” and another called “packages”, and a group_contents table to link them. I have a relationships.ini for the groups table that looks like :-
- Code: Select all
packages.id = group_contents.package_id group_contents.group_id = "$id"
The relationship shows up in the UI as I expect, and if I add a new record, it all works properly - the package record is updated in the package table correctly, and the relationship to the group is set correctly.
However, if I add an existing record, it fails - the package id is set to zero, rather than the id for the package itself. The SQL log shows :-
- Code: Select all
22179 Query INSERT INTO `group_contents` (`group_id`,`package_id`,`type`) VALUES ('1','__packages__auto_increment__','1')
…which is clearly wrong.
I’ve tried assorted relationships.ini files for the other tables - nothing seems to change this behaviour.
Can anyone give me a hint as to what I’m doing wrong?
Thanks!
Vic.
shannah — Tue May 04, 2010 9:01 am
If you make your packages.id field an auto increment field it should work properly.
ccrvic — Tue May 04, 2010 9:23 am
In the table definition? It already is an auto increment field…
Or do you mean there’s a Xataface declaration I’ve got to make?
Vic.
ccrvic — Tue May 04, 2010 9:28 am
Oh - and welcome back, BTW.
Hope your time away was useful…
Vic.
shannah — Tue May 04, 2010 10:21 am
Ok.. then something is wrong. It should replace the marker __packages__auto_increment with the auto increment id from the packages table.
Which version of Xataface, PHP, MySQL are you using. Can you post a minimal test case (table defs, etc..) that I can try to run to confirm the problem?