I'm trying to track down a problem with ChoiceField in Symfony2 but I've run 
into a dead end.
What I'm trying to do is having a user and a group table in the database and 
I want to be able to assign a group to a user using a ChoiceField drop-down.

The Problem is that instead of the correct content in the drop-down it 
actually contains a stack-trace with the following php notice:

PHP Notice:  Object of class Doctrine\\ORM\\Persisters\\BasicEntityPersister 
could not be converted to int in 
/var/www/html/symtest/src/vendor/symfony/src/Symfony/Component/Form/ChoiceField.php
 
on line 118

The User entity contains id, username and ugroup which is defined as 
"@orm:ManyToOne(targetEntity="Group")".
The Group entitiy contains id, name and users which is defined as 
"@orm:OneToMany(targetEntity="User",mappedBy="ugroup")".

The database looks like this:
mysql> select * from user\G
*************************** 1. row ***************************
       id: 1
ugroup_id: 2
 username: dennis
1 row in set (0.00 sec)

mysql> select * from ugroup\G
*************************** 1. row ***************************
  id: 1
name: user
*************************** 2. row ***************************
  id: 2
name: mod
*************************** 3. row ***************************
  id: 3
name: admin
3 rows in set (0.00 sec)

and the controller code like this:

        $em = $this->get('doctrine.orm.entity_manager');
        $urep = $em->getRepository('HelloBundle:User');
        $user = $urep->find(1);

        $form = new Form('user', $user, $this->get('validator') );
        $form->add(new TextField('username'));
        $form->add(new ChoiceField('ugroup',array("choices" => 
array("user","mod","admin")) ));

        return $this->render('HelloBundle:Hello:index.twig', array('name' => 
$name, 'form' => $form));

This is the most simple test-case i could come up with.
Is there anything special that needs to be done to make this work?

Regards,
  Dennis

-- 
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 developers" 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/symfony-devs?hl=en

Reply via email to