best process for saving a new object and its relation in a single call using datamapper |
[eluser]johnmerlino[/eluser]
Hey all, I read the datamapper documentation where it says you can save a new object and its relation in a single call: Code: // Create new User I presume this technique only applies when you create a new object but update another object at the same time. But it doesn't work when creating two new objects: Code: $user = new User(); This writes a new users record to database but not a vanity_urls record. In order to write them both concurrently, I had to do this: Code: user = new User(); The process above works, but not the datamapper documentation example. I presume that's only for when creating a new object in one table but updating one in another. Is my understanding correct? Thanks for response.
[eluser]WanWizard[/eluser]
This is quite logical. When you call save Code: $user->save($vanity_url); You can try to use the fact that all Datamapper methods return the object, perhaps this works (not tested) Code: $user->save($vanity_url->save()); In your second example, you save both objects indivudually, but never make the relation, so you should add Code: $user->save($vanity_url); |
Welcome Guest, Not a member yet? Register Sign In |