2008年8月19日星期二

Re: [fw-db] compound primary key

spaceage wrote:
>
> Is this approach (compound PK) supported in Zend_Table_Db, and if so, how
> does one declare the PK in a class def?
>
> Also, in general, does using this compound key approach present other
> issues with using Zend_Db down the road?
>

Yes, Zend_Db_Table supports compound primary keys (unlike many frameworks).
If your database reports primary keys clearly, Zend_Db_Table should be able
to discover it automatically. You can verify that it's done the right thing
like this:

class Prints extends Zend_Db_Table_Abstract { }
$table = new Prints($db);
$info = $table->info();
print_r($info['primary']);

When you insert a row, just omit the auto_increment field from your row, and
that field will be populated by the database automatically:

$row = $table->createRow();
$row->image_id = 1234;
$row->save();

After you call save() for the new row, the auto-generated id should be
filled in the appropriate column.

print_r($row->toArray());
Array
(
[image_id] => 1234
[sequence] => 1
)

Regards,
Bill Karwin
--
View this message in context: http://www.nabble.com/compound-primary-key-tp19052927p19053701.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: