(Datamapper) One-to-Many Self Relationships [SOLVED] |
[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.
[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.
[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...
[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
[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.
[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
[eluser]Empu[/eluser]
test `table` has no field `selfconnect`. dont forget define 'self_join_as' key in some unusual self-relationships. CMIIW ![]() |
Welcome Guest, Not a member yet? Register Sign In |