Alright, seems like i found a solution.

The issue was that the getter for roles ("getRoles") in my class was
returning $this->roles->toArray() rather than $this->roles

Once i changed this, it worked.

However, this broke the authentication-system, since it relied on the
getter sending an array.

My solution was to use a separate getter, which returned the original
representation.

So i changed the code to:

$form->add(new EntityChoiceField('roleSet',array(
    "class" => 'MyProject\\UserBundle\\Entity\\Role',
    "em"=>$this->get('doctrine.orm.entity_manager')
)));


And, in the User-entity, i have:
public function getRoles() {
    return $this->roles->toArray();
}
public function getRoleSet() {
    return $this->roles;
}




On Apr 6, 3:57 pm, chjacobsen <chjacobsen...@gmail.com> wrote:
> I have a simple form for editing users and, amongst other things,
> assigning them roles.
>
> It works well for authentication when i manually add the right lines
> to the database, and authentication works flawlessly.
>
> However, the following code breaks down:
>
> $form->add(new EntityChoiceField('roles',array(
>     "class" => 'MyProject\\UserBundle\\Entity\\Role',
>     "em"=>$this->get('doctrine.orm.entity_manager')
> )));
> $form->bind($this->get('request'), $user);
>
> The message i get is: "Entities passed to the choice field must be
> managed"
>
> The class exists, the property is correct, the entity manager works,
> and if it matters, the user is previously stored in the database. The
> edit-form works well except for when i add this field.
>
> Any idea about what might be wrong?

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

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

Reply via email to