Datamapper ORM in-table foreign key not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Datamapper ORM in-table foreign key not working (/showthread.php?tid=60788) |
Datamapper ORM in-table foreign key not working - El Forum - 06-29-2014 [eluser]DaMaul[/eluser] For some reason Datamapper is not recognising my in-table foreign key relationship and is attempting to use a joining table instead when I try and access my related object. It's probably the simplest example of such a relationship you could get. Here's what my code looks like: Code: class Venue extends DataMapper Here's the mysql CREATE code for my venues table: Code: CREATE TABLE `venues` ( And here for the towns table: Code: CREATE TABLE `towns` ( When I run the method in the controller, I get a codeigniter DB error stating "Table 'mydatabase.towns_venues' doesn't exist". Obviously datamapper hasn't realised that it can use an in-table foreign key and is looking for a joining table. Can anyone suggest why this is happening? I'm pulling my hair out trying to figure out what's wrong with my setup Datamapper ORM in-table foreign key not working - El Forum - 06-29-2014 [eluser]DaMaul[/eluser] After a load of messinng around, I tried stepping through the code, and it seems like my problem is happening because the code is not correctly initialising the list of fields within the model from the database. The problem seems to be in CodeIgniter's "field_data()" function, which is returning an empty array instead of returning an array of the fields.... Datamapper ORM in-table foreign key not working - El Forum - 06-29-2014 [eluser]DaMaul[/eluser] Ok after a couple of hours of head scratching I think I've solved the problem. I'll post my findings here in case anyone else encounters the same. It seems that the latest version of datamapper relies on the codeigniter's CI_DB_mysql_result::field_data() method, which seems to be totally broken in version 2.2.0 (the latest official release, but it's fixed in the newest dev version). So as far as I can see, the latest version of datamapper doesn't work properly with the latest official release of codeigniter! |