2009年12月3日星期四

Re: [fw-db] Select - insert Zend_Db_Row

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

没有评论: