views:

65

answers:

1

Well it is more like a design question. There are two ways I know to use joins in the Zend Framework

  1. Deal with it using instance of Zend table( its Select obj)
  2. Deal with it using the instance of Zend Db (its Select obj)

in the first approach it seems really strange to me - the some table have to be dealing with other tables too, which is not quite good, messy, at least when I read method name getData() - I assume that it deals with the data of its own.

Second one it is quite better, you can have some class that acts as a service - NodeService, and it will deal with tables node and node_translation ,but it also arises question why would we need Zend Table in this case. I hope I could explain myself good enough thanks.

+1  A: 

Technically, you are refering to Zend_Db_Select and Zend_Db_Table_Select. Zend_Db and Zend_Db_Table do not allow for joining.

From the ZF manual on the Select API in chapter Zend_Db_Table:

The Zend_Db_Table_Select object is an extension of the Zend_Db_Select object that applies specific restrictions to a query. The enhancements and restrictions are:

  • You can elect to return a subset of columns within a fetchRow or fetchAll query. This can provide optimization benefits where returning a large set of results for all columns is not desirable.
  • You can specify columns that evaluate expressions from within the selected table. However this will mean that the returned row or rowset will be readOnly and cannot be used for save() operations. A Zend_Db_Table_Row with readOnly status will throw an exception if a save() operation is attempted.
  • You can allow JOIN clauses on a select to allow multi-table lookups.
  • You can not specify columns from a JOINed tabled to be returned in a row/rowset. Doing so will trigger a PHP error. This was done to ensure the integrity of the Zend_Db_Table is retained. i.e. A Zend_Db_Table_Row should only reference columns derived from its parent table.

The main difference is, Zend_Db_Table and Zend_Db_Table_Select act as a Table Data Gateway, which allows direct access to a table and it's rows and allows to call methods to crud the table, whereas Zend_Db_Select does not and is independent.

Gordon
Yes ur pointing is clear , Just didn't wanna go into details , but still the main question is about the approach where to use the join
simple
@simple Sorry. I thought that was clear from my answer. Use Zend_Db_Select whenever you don't need the added benefit of a Table Data Gateway.
Gordon
Personally I use the Zend_Db_Table_Select 90% of the time (basically all my models extend the Zend_Db_Table_Abstract except models that deal with xml data). I got used to that even though Zend_Db_Select is probably fine most of the time, too.
Richard Knop