Hello,
thanxx for answering,

I tried what you propose, Johathan,
and I now have an UPDATE request,
but,
this request tries to set the dest id to the value of the source object id
(which sounds normal, considering the whole array of values is copied
through the from=>to mechanism).
Then I have a integrity constraint exception, raised because it's trying to
update the PK of te dest row with the one of another row.

so, same problem. I though there could just be a doctrine API to do this
simply (I mean, in one pass).

how to exclude PKs from the copy ?

I could set the dest PK with the good one like this :



$oSource = Doctrine::getTable('MyClass')->find(1);
$oDest = Doctrine::getTable('MyClass')->find(2);

// store the dest id
$myId  = $oDest->id;

$oDest->fromArray($oSource->toArray(false)); // no deep copy required

// reassign dest id
$oDest->id = $myId;

$oDest->save();

and this is weird : it does the work, in so far as I have an UPDATE sql that
set the correct id,
but in the log file this request is followed by a DELETE that should delete
the dest row !  ?

I don't get the logic well here... and I'm a bit surprised I have to use
this workaround. I thought there could be a simple method to do this common
task in Doctrine API. But did not found.

any other ideas ?



2009/6/29 Jonathan Wage <jonw...@gmail.com>

> Maybe this is what you want?
>
> $oSource = Doctrine::getTable('MyClass')->find(1);
> $oDest = Doctrine::getTable('MyClass')->find(2);
>
> $oDest->fromArray($oSource->toArray(false)); // no deep copy required
> $oDest->save();
>
> - Jon
>
>
> On Mon, Jun 29, 2009 at 12:39 PM, Jess OVR <jess...@gmail.com> wrote:
>
>> Hi all
>>
>> I'm quite new to Doctrine, but I've already made several project with
>> Propel.
>>
>> I would like to make a clone copy from a Doctrine object to another (both
>> existting in the db), so, reading the Doctrine doc, I tried :
>>
>> $oSource = Doctrine::getTable('MyClass')->find(1);
>> $oDest = Doctrine::getTable('MyClass')->find(2);
>>
>> $oDest = $oSource->copy(false); // no deep copy required
>> $oDest->save();
>>
>> but this drives to an INSERT, where I'm expecting an UPDATE.
>> I thought save() method was smart enough to guess it's an UPDATE, and not
>> an INSERT (because $oDes obj is instantiated from db fetching, and not with
>> a new() call) ...
>>
>> How to copy all data exept the PK, and then update the object ?
>>
>> thank for any help :)
>>
>> ps : note this is a copy of my post :
>> http://forum.symfony-project.org/index.php/t/21565/
>>
>>
>>
>
>
> --
> Jonathan H. Wage (+1 415 992 5468)
> Open Source Software Developer & Evangelist
> sensiolabs.com | jwage.com | doctrine-project.org | symfony-project.org
>
> You can contact Jonathan about Doctrine, Symfony and Open-Source or for
> training, consulting, application development, or business related questions
> at jonathan.w...@sensio.com
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to