Skip to content
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

[Doctrine][Bridge] EntityType : default choices value #2504

Closed
wants to merge 6 commits into from
Closed

[Doctrine][Bridge] EntityType : default choices value #2504

wants to merge 6 commits into from

Conversation

RapotOR
Copy link
Contributor

@RapotOR RapotOR commented Oct 28, 2011

If the choices property is equal to array(), the EntityChoiceList don't use empty choices and try query_builder or findAll.

We should use false as default instead of array() to be able to have an empty list if a custom filter gives an empty result. With array() as default, the EntityType populates choices with findAll even if our result was empty; and it is not expected.

(PR created instead of #2500 to pull it into 2.0 branch)

@beberlei
Copy link
Contributor

beberlei commented Nov 1, 2011

This is valid, however as a fix i am not sure if an is_array() check would be better here, since "null" now fails for this case as well.

@ericclemmons
Copy link
Contributor

First, it would be useful if you went ahead & created a test case (that would fail on 2.0) illustrating how it's darn near impossible to have empty choices.

Second, I would assume the behavior would be the following because of semantics:

  • Default options uses "choices" => null. NULL should be any uninitialized state so we can distinguish between user-set values.
  • If a user wants an empty list, they should explicitly use an empty array() for choices.
  • The check would then be if (is_array($choices)) { ... }.
  • false or null should not be allowed options, as neither are a collection of "choices".

@RapotOR
Copy link
Contributor Author

RapotOR commented Nov 2, 2011

It is my first PR and I was quite lost regarding PR.

Thanks for advises. It makes sense.
If the null value is the chosen way, the issue affects also ArrayChoiceList because it accept array for the choices options. A way is to avoid the _ArrayChoiceList::_construct

@ericclemmons
Copy link
Contributor

We'll have to get some feedback from @beberlei. I'm usually hesitant to encourage extra work, since sometimes simple improvements go through a lot of architecture discussions. (Especially considering the required change to ArrayChoiceList, which I forgot was used via parent::__construct)

@RapotOR
Copy link
Contributor Author

RapotOR commented Nov 5, 2011

Some coments:
The parent::__construct only checks the $choice type (array or closure). As the null value should be added to admitted types, I guess it makes sense to replace the parent::__construct by new check allowing null too. I think there is no utility to change the ArrayChoiceList because an empty array works with array().

@fabpot
Copy link
Member

fabpot commented Nov 22, 2011

@beberlei: Can you comment on this PR?

@webda2l
Copy link

webda2l commented Dec 12, 2011

+1

@beberlei
Copy link
Contributor

@fabpot You can merge this PR, its good this way.

@fabpot
Copy link
Member

fabpot commented Dec 13, 2011

@RapotOR: Can you squash your commits before I merge this PR? Thanks.

@stof
Copy link
Member

stof commented Dec 13, 2011

it also need to be rebased on top of master as github says it conflicts

@RapotOR
Copy link
Contributor Author

RapotOR commented Dec 13, 2011

I've squashed the commits and github created a new PR #2868. I close this one.

@RapotOR RapotOR closed this Dec 13, 2011
fabpot added a commit that referenced this pull request Dec 13, 2011
Commits
-------

4d64d90 Allow empty result; change default *choices* value to **null** instead of **array()**. - added *testEmptyChoicesAreManaged* test - `null` as default value for choices. - is_array() used to test if choices are user-defined. - `null` as default value in __construct too. - `null` as default value for choices in EntityType.

Discussion
----------

[Doctrine][Bridge] EntityType: Allow empty result; default `choices` value changed to null

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
References the following tickets: #2504

- added *testEmptyChoicesAreManaged* test
- `null` as default value for choices.
-  is_array() used to test if choices are user-defined.
- `null` as default value in __construct too.
- `null` as default value for choices in EntityType.

I squashed commits from PR #2504 as requested.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants