2009年12月4日星期五

Re: [fw-db] Select - insert Zend_Db_Row

I agree, and thats what I do now. I just find

$row = $this->find($id)->current();
$row->setTable(new My_Model_History());
$row->save();

more elegant, but it throws exception :P

Regards,
Saša Stamenković


On Thu, Dec 3, 2009 at 4:12 PM, Ralph Schindler <ralph.schindler@zend.com> wrote:


umpirsky wrote:
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?

insert() will return the primary key, if you then wanted the actual Row object, you'd have to select it from the table again.  If you create the row first, then after save, you already have a Row object attached to the database row.

It depends on what you plan on doing after this code.  If you don't need a row object, then insert() shall work just fine :)

-ralph

没有评论: