[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) |
[eluser]OverZealous[/eluser]
@Alface Could you please reword your question? I am having difficulty understanding what you are asking. Thanks.
[eluser]Alface[/eluser]
[quote author="OverZealous" date="1256706587"]@Alface Could you please reword your question? I am having difficulty understanding what you are asking. Thanks.[/quote] You told me to make an array of objects, and I wanna know if there is a way to put all 'link' on a single object of Video, and just save it like this: Code: $va->save($v); And result on several entries on data base.. thanks I created a function extending the array extension: Code: function from_array_all($data, $fields = '', $save = FALSE){ but I'm still can't save if using Code: $va->from_array($_POST); :down:
[eluser]OverZealous[/eluser]
Every object you create must be saved using the ->save() method individually. Calling $object1->save($object2) does not save $object2, and in fact may throw an error because DMZ assumes all related objects are already saved. If you need to save a bunch of items in different locations, you can write an extension for your needs, or just write a CI library.
[eluser]Alface[/eluser]
But on the manual of DMZ it shows it: Code: // Let's relate the user to these books
[eluser]OverZealous[/eluser]
Yes, but all of the books have already been saved. That call will do two things: 1) Save the User object (if it hasn't already been saved) 2) Create relationships between that User and all books in the All array. It does not save the books. They must already be saved. I'm not going to find it, but it explains this in the manual.
[eluser]BrianDHall[/eluser]
@Alface If you have or can relatively easily get all the objects you want to save in an array you could save them like so: Code: foreach ($videos as $video) Then you can just run a save of I guess $link->save($videos), or somesuch.
[eluser]Alface[/eluser]
Now I understand, but there is no way of save 'videos' just if 'videosalbum' sucefull save first and vice versa? Thank you very much
[eluser]OverZealous[/eluser]
@Alface The only way to do this — no matter how you set it up — is using SQL transactions. Code: $videoalbum = new VideoAlbum(); Edit: I should mention that the transaction is universal. It will succeed or fail everything you try to change on the database between there.
[eluser]Alface[/eluser]
Yep, I know transaction, I use: $config['auto_transaction'] = TRUE; It shouldn't supply it?
[eluser]OverZealous[/eluser]
Auto-transactions (another legacy element from the original DM) only help within a single call to ->save(). If you are trying to save multiple objects, you need to manually manage transactions. There is no way for DMZ to know that you are trying to group multiple saves together otherwise. If it was completely up to me, I'd dump the auto-transaction thing altogether, because it doesn't make much sense, or provide much benefit. I never updated updated that page of the manual, so it doesn't say this. I probably should remove the section on auto-transaction eventually. |
Welcome Guest, Not a member yet? Register Sign In |