[DataMapper] (1.7.1) Relation saving issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [DataMapper] (1.7.1) Relation saving issue (/showthread.php?tid=37109) |
[DataMapper] (1.7.1) Relation saving issue - El Forum - 12-28-2010 [eluser]grisha[/eluser] Hello there. Today I've tried to implement DM 1.7.1 into one of my projects. Following the guide provided by DM developer I've encountered a problem. The Contractor Creation method is like this: Code: $c = new CContractor(); The Code: $this->customer The contractor is being added properly to the database. Just before the call of Code: $this->customer->save($c) I'm not sure if it isn't a bug or smth. In the end I've got: Code: Unable to relate customer with ccontractor. Am I doing something wrong? [DataMapper] (1.7.1) Relation saving issue - El Forum - 12-28-2010 [eluser]WanWizard[/eluser] You get this message if you don't have a valid relationship defined between both models (note: you have to do this in BOTH models). Show me the relationship definitions from both the Ccontractor and the Customer model if you want me to have a look. [DataMapper] (1.7.1) Relation saving issue - El Forum - 12-28-2010 [eluser]grisha[/eluser] The relation is defined by the code fragments listed below: file: models/crm/customer.php Code: class Customer extends DataMapper file: models/customer/company/ccontractor.php Code: class CContractor extends DataMapper [DataMapper] (1.7.1) Relation saving issue - El Forum - 12-28-2010 [eluser]sooner[/eluser] Class names must have the first letter capitalized with the rest of the name lowercase..this is what i find in the models user guide of codeigniter...it may be because of that..but i am not sure.. [DataMapper] (1.7.1) Relation saving issue - El Forum - 12-28-2010 [eluser]WanWizard[/eluser] That is correct. The lookup of the relation happens using the capitalized name of the model, unless you use an advanced relationship definition (with an array instead of a string), in which case the class name will be used as defined. This this case, it can't find a relation for Customer called 'Ccontractor'. Either define them as stated in the manual, or use an advanced relationship definition so you can name them whatever you want. [DataMapper] (1.7.1) Relation saving issue - El Forum - 12-28-2010 [eluser]grisha[/eluser] Looks like it is the solution Thanks guys. The code below is a example solution for this problem: Code: class Customer extends DataMapper Thanks once again. I would recommend extending the error description text, so you can avoid such questions in future [DataMapper] (1.7.1) Relation saving issue - El Forum - 12-28-2010 [eluser]WanWizard[/eluser] Well, I thought the message was self explanatory: Quote:Unable to relate customer with ccontractor.i.e. "Help, I can't find the relationship between the two". |