Sunday 15 January 2012

doctrine2 - Doctrine 2 get join field name -


I want to meet the field name, but how do I get it? I have a scenerio like this, for example I have 2 tables and roles. There is a collection of roles in the user unit which is a collection. I need a method that is receiving a parameter relayed object (roles) and it should return role_id which is the user's foreign key. I did not find any way

Below is the declaration of your institutions:

  / ** * @ORM \ unit * / class user {/ ** * @ORM \ ManyToMany (target = "role") * / private $ roles; / ** * Returns \ Principles / Common \ Collections \ Collections * / Public Function getRoles () {Return $ this-> Roles; } // Other fields and methods // ...} / ** * @ORM \ unit * / class role {/ ** * @ORM \ column (name = "id", type = "integer") * @ORM \ Id * @ORM \ value generated (strategy = "auto") * / personal $ id; / ** * @ integer integer * / public function getId () {return $ this- & gt; Id; } // Other Fields and Methods // ...}   

You can call to retrieve the ID:

  $ user = $ This- & gt; GetUser (); $ RoleIDs = $ user- & gt; GetRoles () - & gt; Map (function (role $ role) {return $ role-> getId ();});   

Another option is to use theory communication to get raw results.

No comments:

Post a Comment