Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Many to Many choice list bug #9550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
i-void opened this issue Nov 20, 2013 · 2 comments
Closed

Many to Many choice list bug #9550

i-void opened this issue Nov 20, 2013 · 2 comments
Labels

Comments

@i-void
Copy link

i-void commented Nov 20, 2013

I debug myself a bug which you can reproduce by using propel1's model form field type in a form. I used the field type for many to many relation to render a multi selectable checkgroup;

                $builder->add('products', 'model', array(
                    'class' => 'Acme\XXBundle\Model\Product',
                    'property' => 'name',
                    'label' => ' ',
                    'expanded' => true,
                    'multiple' => true,
                    'attr' => ['class'=>'css-checkbox'],
                ));

this is for Company->Follows<-Products (Many company can follow many product)
but when rendered the form followed products didn't come ticked for the company. I debug and the problem is on vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php in the getValuesForChoices function. In this function
if ($choice === $givenChoice) { will not work for classes. You must change this to if ($choice == $givenChoice) {. I tested and now it can tick the choices which are on the follow table.

@stof
Copy link
Member

stof commented Nov 23, 2013

Comparing by identity is intended. Comparing objects by value can create very weird results, as it compares all properties in the object graph (this can even create an infinite loop if you object graph is cyclic).

Note that in the case of Doctrine, you always get a single instance for a given entity, so the comparison works well.

If Propel gives several instances for the same row, it would indeed be tricky (Propel gives you a equals method to do the comparison, but this works only for code aware of Propel to use it)

@webmozart
Copy link
Contributor

This was fixed by #10572.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants