php - Is there a way to remove multiple attribute to a doctrine ObjectSelect? -


I have 3 tables, users, roles and UserRoles. The I user can have only one role, but I I did not want to add a column for the role in the table, the problem is that I want to add an object selection as a user, but it is printing as a multiple selection, which I do not want, I have been removed Attribute ('multiple') Tried to add but I get an error saying:

"Form Selects does not allow multiple selected values ​​to be specified when the element has no multiple attribute

Multiple additions: False, neither does it work, so I am trying to explain it, this is the code.

User Unit:

  / ** * @ORM \ manyToMany (targetEntity = "AUTH \ unit \ user \ roles") * @ORM \ JoinTable (name = "userRole", * joinColumns = {@ ORM} JoinColumn (name = "idUser", referenced column name = "id", exclusive = true}}, * Inverazonge column = {@ ORM \ JoinColumn (name = "idRole", referenced column name = "id")} * * @ annotation * @ Annotation \ op ("label": "roll", "target_class": "atoth" Unit \ user \ roles "," property ":" name "}) * @ annotation \ properties ({" class ":" form-control "}) ** / private $ roles; Public function __ composition () {$ this- & gt; Roles = New ArrayCollection (); } Public Function getRoles () {Return $ this- & gt; Roles & gt; GetValues ​​(); }  

Add AdminController action:

  public function addUserAction () {$ view = new ViewModel (); $ UserEntity = New User (); $ Em = $ this- & gt; Unit manager (); $ Creator = new theory annotation builder ($ em); $ Form = $ builder-> CreateForm ($ userEntity); $ Form-> Setholder (new empiricator ($ em, 'user \ unit \ user')); $ Form & gt; Dam ($ userEntity); $ Request = $ this- & gt; GetRequest (); If ($ request-> ispost ()) {$ form-> SetData ($ request-> getPost ()); If ($ form-> isValid ()) {$ em- & gt; Continues ($ userEntity); $ Em- & gt; Flush (); }} $ View- & gt; Form = $ form; Return $ view; }  

and my thoughts:

  $ form = $ this-> Form; $ Form-> Set Attribute ('Action', $ this- & gt; URL ('Admin', array ('action' => 'adduser'))); $ Form & gt; ready (); Echo $ the-> Form () - & gt; OpenTag ($ form); Echo $ this-> Formwork ($ form- & gt; receive ('username')); Echo $ this-> Formaro ($ form-> receive ('email')); Echo $ this-> Formwork ($ form- & gt; receive ('roles')); Copy $ this- & gt; Submit Form ($ form-> Receive ('Submit')); Echo $ the-> Form () - & gt; CloseTag ();  

If there is only one role in the user, why many of the many relationships ?

The error then raises when selection rendering occurs. Function code is:

  Validate the secure functionMultiValue ($ value, array $ attributes) {function    if (void === $ Value) {return array (); } If (! Is_array ($ value)) {return (array) $ value; } ($ Attributes ['multiple'])!! $ Attributes ['multiple']) {Enter new exception  

The way you defined your user unit, you will always have an array:

  (...) public function __construct ( ) {$ This-> Roles = New ArrayCollection (); } (...)  

so it always comes past, if it checks the multiple attribute. Due to this you do not want to be multiple, you set this property wrong, and then when the error occurs. If it recognizes an array, then the selection is expected to be very high.

If you change this relationship, then your code should work. You can try one of many, in this way, from the role unit, you can get all the users with the role of XXX. And from the user side, you can get the user's only role.


Edit:

Sorry, now I see why you have so many relationships with many joining tables This is a lot of relation from one to the other. It seems that there is no one in the table joining ... The normal way of doing this is to think that the role Strong> should keep columns, but you can not role property to roles property Minister need not role an array of institutions.



Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -