thinking a bit about it, I guess Zend_Db_Table does its job properly.
I still think there are cases where you'd like to interface with a 'table',
which could be a view, without having to have that table in a relational
schema (utility tables, like log tables). I am still not convinced a Table
Data Gateway design pattern has anything to do with handling unicity/primary
keys, is there any documentation that clearly specifies that? I still think
it's out of the pattern's scope.
Ideally, Zend_Db_Table_Abstract would derive from an ancestor class (for
example, Zend_Db_TableDataGateway) which would only take care of stupidly
mapping to a table or view without any logic related to relations. You
wouldn't have the find() method, but all functionality that don't depend on
primary keys like fetchAll(), insert, delete and update (that don't take
primary keys as parameter, only a list of wheres) etc would be implemented
in that class. Zend_Db_Table would implement primary key and relational
functionality.
What is your thoughts on "views" ? Do you think people should avoid using
Zend_Db_Table for views, or do you agree with different implementations
found on the web where people simply subclass Zend_Db_Table and disable the
check on the primary keys?
Anyhow, I still think Zend_Db is some piece of solid OOP design!
Ralph Schindler-2 wrote:
>
> In general, for the longevity of the project, I would warn against a
> keyless table. Its generally considered bad practice which is not an
> issue now, but when the next developer wants to add features to the
> project, they might find themselves in a hard time without alot of
> refactoring.
>
> Primary/Identity keys are essential to the design of Zend_Db_Table. Its
> not something we came up with, its the best-practice design we used as
> inspiration:
>
> http://martinfowler.com/eaaCatalog/tableDataGateway.html
>
> In fact, its further described as its own pattern:
>
> http://martinfowler.com/eaaCatalog/identityMap.html
>
> That aside, did you try using Zend_Db_Table by adding all columns as the
> primary key?
>
> for example:
>
> class MyTable extends Zend_Db_Table_Abstract {
> protected $_primary = array('ip', 'visit', ...);
> }
>
> YMMV, but it should work for basic operations like insert, and
> non-find() based selects. Delete and update will be hard b/c you'll
> need to supply something to act as the identity column. You might also
> find problems with the row-data gateway (Zend_Db_Table_Row), since
> save() and delete() will want an identity to key off of.
>
> Hope you can use some parts of the table/row gateway to do what you want.
>
> -ralph
>
--
View this message in context: http://www.nabble.com/Zend_Db_Table-and-primary-keys...-tp25117083p25151383.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论