CodeIgniter Forums
[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: [Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) (/showthread.php?tid=23751)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[eluser]OverZealous[/eluser]
@Alface
Could you please reword your question? I am having difficulty understanding what you are asking. Thanks.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[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){
    foreach($data as $subdata){
        $this->from_array($subdata, $fields, $save);
    }
    return $this;
}

but I'm still can't save if using
Code:
$va->from_array($_POST);
$v->from_array_all($this->input->post('videos'));
$va->save($v)

:down:


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[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.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[eluser]Alface[/eluser]
But on the manual of DMZ it shows it:
Code:
// Let's relate the user to these books
$u->save($b->all);



[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[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.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[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)
{
    $video->save();
}

Then you can just run a save of I guess $link->save($videos), or somesuch.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[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


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[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();
$videoalbum->trans_start();

// process all of your saves

$videoalbum->trans_complete();

Edit: I should mention that the transaction is universal. It will succeed or fail everything you try to change on the database between there.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[eluser]Alface[/eluser]
Yep, I know transaction, I use:
$config['auto_transaction'] = TRUE;

It shouldn't supply it?


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 10-27-2009

[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.