2009年1月21日星期三

Re: [fw-db] Saving a Zend_Db_Table_Row with relationships

Hi Christer, I think this is a very common scenario; thanks for asking the question. I'd be intersted as well as to how this has been tackled by other developers.

Cheers,
Mike

On Wed, Jan 21, 2009 at 11:37 AM, Christer Edvartsen <cogo@starzinger.net> wrote:
Lets say we have a users table, a groups table and an intersection table called usergroups. I my application I have a Users class to represent the users table (extends Zend_Db_Table) and a User class to represent one user (extends Zend_Db_Table_Row). The same goes for the other tables as well.

Now ... lets say we have a form where we want to edit a user (including adding/removing groups). How would you guys go about implementing the saving of the user object and the group relationships?

I'm thinking of writing a custom save() method in the User class that first calls parent::save() to save the user to the users table, and then implement stuff for saving data to the usergroups intersection table. I would also need to add some attributes to the User class and make sure the group relationshis is loaded when a User object is created. Is this the "regular" way of solving this or does Zend_Db have some kind of magic stuff to handle this?

How do other people solve this?


--
Christer Edvartsen
cogo@starzinger.net
http://cogo.wordpress.com/



--
Celebrate Liberty, Freedom, and Rights at http://www.theconstitutionalist.us.

没有评论: