Infuriatingly Simple Datamapper Relationship problem |
[eluser]kungpoo[/eluser]
I've been tearing my hair out tonight, something that I know has worked for me in the past just doesn't seem to work anymore. To illustrate I have done a fresh install of CI and DMZ on both CI 1.7.2 and 2.0. Inserted the following into a DB (as simple as possible) - Code: CREATE TABLE `artists` ( Created the models- Code: <?php Code: <?php Then did the controller - Code: <?php But all I get is the following queries being run, the relationship is never created. If the objects are saved separately they are fine but obviously there is no relationship then. Code: SELECT * FROM `artists` LIMIT 1 I've tried it with simple one to one and one to many relationships too but nothing seems to be working for me. Am I missing something glaringly obvious? Thanks!
[eluser]Jelmer[/eluser]
I don't really know DMZ, only played around with it a little bit and ended up using another ORM. But in general I would expect that you'd have to tell the system it's not just a "has many" (one-to-many) but a "has and belongs to many" (many-to-many) relationship. Also, I'd expect you have to save the first object before attaching the second. And maybe save the second object before establishing the relation between the two.
[eluser]kungpoo[/eluser]
Thanks for trying to help Jelmer. As far as I can tell that is all the syntax that the models require. Saving the models first individually and then retreiving them to create a join works but seems quite a roundabout way of doing it? In the DMZ docs http://www.overzealous.com/dmz/pages/save.html there is a section that explains what I am trying to do but I cannot seem to replicate it although I am sure I've had it working in the past. Code: //Save a New object and its Relations in a single call Thanks again
[eluser]kungpoo[/eluser]
Looking at it I think it might be that I can't create 2 objects and save the relationship on-the-fly, which is more or less what you were getting at. Thankfully it works with one being created and then joined to the selected one. I suppose that must have been what I was doing when I had a similar setup working before |
Welcome Guest, Not a member yet? Register Sign In |