Hi Fabien, Thanks for the answer. Since the group was supposed to be added automatically, I had the groups_list widget unset in my form. The function you pointed me to seems to take what was stored in that variable and link the values to the user being registered. I assume I can get this working by making the groups_list field a hidden one and setting the default value on the action or even on the form code itself - then the code line you pointed out would do ther rest. However, I'm unsure about how safe this is - couldn't an user deliberately change the value of my hidden groups_list field in an attempt to be added to another group, one with a different permission set?
Best Regards, Campezzi On May 25, 12:53 pm, "FlyLM [ML]" <flylm...@gmail.com> wrote: > Hi, > > If you have always sfDoctrineGuardPlugin installed, take a look at > this file line 84 (savegroupsList method) > > /lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesGuardUserForm.class.php > > => $this->object->link('groups', array_values($link)); > > Fabien > > 2009/5/25 Campezzi <campe...@gmail.com>: > > > > > Hi there! > > > I'm getting started with sfDoctrineGuardPlugin and after doing a few > > tutorials, I started to implement it in one of my projects. I have > > created a registration form and embedded the Profile class form. So > > far, so good - whenever a new user registers, both the sfGuardUser and > > Profile objects get saved to the database and are correctly > > associated. > > > Now, I have a "users" sfGuardGroup with a set of permissions (its id > > is 1), and I'd like to put all members who sign up via this > > registration form automatically in this group. My first idea was to > > override the save() method of the Profile model to do that: > > > class Profile extends BaseProfile > > { > > public function save(Doctrine_Connection $conn = null) > > { > > $ret = parent::save($conn); > > > $relation = new sfGuardUserGroup(); > > $relation->user_id = $this->sf_guard_user_id; > > $relation->group_id = 1; > > $relation->save(); > > > return $ret; > > } > > } > > > However, when I try to add a new user through the form I get a SQL > > error: > > > SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry > > '5-1' for key 'PRIMARY' > > > ... where 5 is the id of the newly created sfGuardUser and 1 is the id > > of the sfGuardGroup I'm trying to add the user to. Of course, I > > checked the database and there are no other sfGuardUserGroup objects > > with the 5-1 key combination, hence it's not a duplicate record thing. > > > I tried searching around, but found nothing about this error other > > than a few complaints about the save() method not being called on > > objects saved through embedded forms. It seems that is the issue here > > - I'm trying to create a many-to-many relation, but the user is not > > yet saved to the database when I try saving the relation, so the > > database throws an error because I'm adding a reference to an object > > that does not exist. However, if that is really the problem, isn't it > > weird that my profile actually has its sf_guard_user_id property set?! > > > So, the 64.5 million dollar question: how do I get this to act like I > > expect it to do? :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---