(Datamapper) One-to-Many Self Relationships [SOLVED] - 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) One-to-Many Self Relationships [SOLVED] (/showthread.php?tid=44240) |
(Datamapper) One-to-Many Self Relationships [SOLVED] - El Forum - 08-08-2011 [eluser]Empu[/eluser] Hi... I have a problem with a one-to-many self relationships How to describe a model for the table: Code: `id` int(5) unsigned NOT NULL AUTO_INCREMENT, I tried with the code: Code: /* model */ Quote:Fatal error: Cannot use object of type Organization as array in Z:\htdocs\application\libraries\datamapper.php on line 2817 I tried looking in the manual, but could not find guides for it. Thanks for helping Note: im using CI2, Datamapper1.8.1 and HMVC. (Datamapper) One-to-Many Self Relationships [SOLVED] - El Forum - 08-09-2011 [eluser]WanWizard[/eluser] Read this page carefully: http://datamapper.wanwizard.eu/pages/reservednames.html The reason you get these errors is that you use the reserved word 'parent' here. By doing so, you'll overwrite the value of the objects parent relation. Replace 'parent' by 'holding' and it will work fine. p.s. the 'join_self_as' on the has_one is not needed, it works fine without. (Datamapper) One-to-Many Self Relationships [SOLVED] - El Forum - 08-09-2011 [eluser]Empu[/eluser] That was my mistake, does not read the manual carefully. Now the databases structure to be like this, Code: `id` int(5) unsigned NOT NULL AUTO_INCREMENT, and the model & controller to be like this, Code: /* model */ As you say, it's work fine. Thanks so much... (Datamapper) One-to-Many Self Relationships [SOLVED] - El Forum - 08-10-2011 [eluser]valuk[/eluser] Hi, I have the same problem with different error. Quote:Table 'najdiobrtnika.selfconnects_tests' doesn't exist Model Code: var $has_one = array Table Test id test_id title Any ideas? Thanks (Datamapper) One-to-Many Self Relationships [SOLVED] - El Forum - 08-10-2011 [eluser]WanWizard[/eluser] Difficult to comment as you don't provide all information. What is 'naziv'? You select it, but it isn't part of your test table? What was the query you constructed? You will get these kind of errors when Datamapper can't find the foreign key in the has_many table, and then assumes that you're using a relationship table instead. (Datamapper) One-to-Many Self Relationships [SOLVED] - El Forum - 08-10-2011 [eluser]valuk[/eluser] Sorry. Naziv is same as title. So insted of title I used naziv. Controller Code: t = new Test(); Is it better? I notice that this error occured if I used filed name test_id. If I replace it with self_id or holding it is OK. Thanks (Datamapper) One-to-Many Self Relationships [SOLVED] - El Forum - 08-10-2011 [eluser]Empu[/eluser] test `table` has no field `selfconnect`. dont forget define 'self_join_as' key in some unusual self-relationships. CMIIW |