2009年11月30日星期一

Re: [fw-db] Select - insert Zend_Db_Row

Hehum.

$row = $this->find($id)->current();
$carHistory = new Automobili_Model_CarHistory();
$carHistory->insert($row->toArray());

is shorter then yours

$row = $this->find($id)->current(); 
$historyTable = new My_Model_CarHistory(); 
$historyRow = $historyTable->createRow($row->toArray()); 
$historyRow->save(); 

and maybe faster, isn't it?

What is the advantage of your approach?

Thanks for the response!

Regards,
Saša Stamenković


On Mon, Nov 30, 2009 at 9:05 PM, Ralph Schindler-2 [via Zend Framework Community] <[hidden email]> wrote:
Hi,

Perhaps something like this-


$row = $this->find($id)->current();
$historyTable = new My_Model_CarHistory();
$historyRow = $historyTable->createRow($row->toArray());
$historyRow->save();

This assumes that you want the primary keys to be the same.  Otherwise
you might have to do this:

$data = $row->toArray();
unset($data['id');

before inserting it into the createRow() method, to ensure that it gets
it's own database provided primary key.

Hope that helps,
Ralph

umpirsky wrote:

> Hi.
>
> I tried (in my class which extends Zend_Db_Table_Abstract):
>
> $row = $this->find($id)->current();
> $row->setTable(new My_Model_History());
> $row->save();
>
> My_Model_History and current class have same mysql structure, identical
> tables, one is active, and other I want to use for data history.
>
> I got:
>
> Zend_Db_Table_Row_Exception: Cannot refresh row as parent is missing
> thrown in Zend\Db\Table\Row\Abstract.php on line 758
>
> It works with:
>
> $row = $this->find($id)->current();
> $history = new My_Model_CarHistory();
> $history->insert($row->toArray());
>
> Is there a way to do it with sth similar to 1st example, or there is maybe
> some other better option?
>
> Regards,
> Sasa Stamenkovic.



View this message in context: Re: [fw-db] Select - insert Zend_Db_Row
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: