I would do that in beforeSave(). What problems were you having with that? On Wed, Mar 4, 2009 at 1:34 PM, foldiman <[email protected]> wrote: > > I've successfully setup a HABTM between a User model and Club model > that looks like this in my User model: > var $hasAndBelongsToMany = array( > 'Club' =>array( > 'className' => 'Club', > 'foreignKey' => 'user_id', > 'associationForeignKey' => 'club_id' > ) > ); > > When creating new Users, I display a select field using the following > in my Controller. > > $this->set('clubs', $this->User->Club->find('list')); > > However, after saving a new user, I only want to insert records into > my clubs_users table for certain types of Users. For example, if a > User is a 'Club Administrator', they can have a relationship with a > Club. If they are an 'Anonymous User', I don't want to associate them > with a Club. > > I've successfully got this running by using jQuery to hide and show > the Clubs select field on the add new User page according to a > preceding User Role field. jQuery actually sets the Clubs field's name > to 'null' when hidden so Cake ignores the field. However, this sees > like a fragile system. > > Is there a built in way in Cake to achieve the same results? Maybe in > the beforeSave() callback in the User model to intercept and kill the > clubs_users table insert? I've tried a few things there without luck. > Any help would be appreciated. Thanks. > > > >
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
