2010年6月1日星期二

Re: [fw-db] Duplicate field names in manytomany relationship


On Jun 1, 2010, at 12:36 AM, Steve Rayner wrote:

Zend_Db_Table encourages us to use a field name of id for the primary key for each table (i know we can override it).

Actually, Zend_Db_Table has no default for the name for your primary key.  You may be thinking of Ruby on Rails or perhaps some other PHP frameworks.  :-)

If you don't declare the $_primary attribute of your Table class, Zend_Db_Table defaults to the column (or columns) declared as the primary key in your database.  It queries the table metadata when you instantiate the Table object.  If it still can't find a primary key, it throws an exception.  There is no default of "id" or any other name.

Anyway, I'm glad you found that renaming your primary key columns resolved the ambiguity.

Regards,
Bill Karwin

没有评论: