What is the advantage of using a DataMapper with Zend_Db_Table as opposed to only using a DataMapper w/ the database adapter directly?

In general, I see Zend_Db_Table as a quick and easy way to do single-table queries.

In general, I see Zend_Db_Table as a quick and easy way to do single-table queries. You can surely do joins with Zend_Db_Table, but since the class is targeted towards a specific table (after all, it is intended as a Table Data Gateway implementation), all such joins always feel - to me, at least - like an unnatural graft. In that case, I always tend towards straight adapter-based queries with joins, that could include your transaction handling.

Of course, in either case, it is certainly desirable to put all of this behind a model or mapper or service layer. Then, as you change these implementation details- say, start out with a Zend_Db_Table implementation, but later realize you need to join data from a another table, so you move to adapter-based queries - none of this will affect consumers of the model/mapper/service. Hope this helps.

Thx David, that helps a lot. Also, if i'm using a datamapper, which maps the zend_db_row objects to the domain model, and thus, i'll need to invoke a datamapper::save($domainModel) rather than $zend_db_table_row_object->save(), does that mean all the overhead for zend_db_table_row is being wasted? And therefore, I should just perform the queries directly via database adapters?

Additionally, when would anyone use a zend_db_table_row insert method over a zend_db_table insert? Thx so much for your time David, mucho appreciated! – blacktie24 Feb 25 at 23:46 I agree that if you are using a $dataMapper->save($domainModel), then the overhead for Zend_Db_Table_Row is being wasted.

Your second question - calling insert() on Zend_Db_Table vs calling it on Zend_db_Table_Row is really interesting. I'll have to poke around a bit. Anyone else with insight on this particular point, I'd also be interested to hear.

– David Weinraub Feb 26 at 7:00.

The way I see it, you want your code to be as Object Orientated as possible for maintainability and testability. I guess it depends what other solution you would implement instead, but if the alternative is raw, bespoke SQL queries scattered arbitrarily around your code base and being passed around as arrays with whatever key values seemed appropriate in a particular instance, mappers and table gateways are much more structured. Your code will be more reusable.

Also, If you have an object representing a table row, you can dummy that object for unit testing. It depends what your asking I guess, I'm being pretty high level and listing the advantages (as I understand them) against not using a model pattern at all... Anyway, hope it helps :).

Really appreciate the input! I think I was a bit unclear though, and have since edited my post title and description. I am definitely planning on using a datamapper, but i'm wondering if I should use the Zend_Db_Table with it or just use the Zend_Db_Adapter directly?

– blacktie24 Feb 25 at 9:03 Just using the adapter can get messy. Its better to model your tables and deal with those in your mappers. Then you get to use table find, insert etc.To interact with your data :) I feel like everything's simpler if your database structure is modelled in your application.

– PeterL Feb 25 at 9:47 that makes a lot of senses actually. Posted this followup above, but will repost again. If i'm using a datamapper, which maps the zend_db_row objects to the domain model, and thus, i'll need to invoke a datamapper::save($domainModel) rather than $zend_db_table_row_object->save(), does that mean all the overhead for zend_db_table_row is being wasted?

And therefore, I should just perform the queries directly via database adapters? Additionally, when would anyone use a zend_db_table_row insert method over a zend_db_table insert? Thx again for your help Peter!

– blacktie24 Feb 25 at 23:50 (sorry for the belated response I've been on holiday) Fair warning: I'm not convinced this is right but this is how it seems to me :p OK datamapper save would use zend_db_table save, as the datamapper would itself have a zend_db_table. You're also unlikely to call it with a model argument, but I guess that depends how you're app is structured.PTO... – PeterL Mar 7 at 8:55 When you use zend db table find you get a table row back (or a rowset), thats what is saved. You don't need to talk about / explicitly model rows unless you want to override the default behaviour some way.

I.e. Don't model a row unless you need to and don't explicitly work with rows unless you arrive at a row through a table. But effectively you're always working with rows.

Does that make sense? :) – PeterL Mar 7 at 8:59.

For example if you want to modify data from db Or if you need to send mails to peoples on insert records and so on..

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions