Monday 15 April 2013

sql - Symfony Doctrine : Use real tablename in request -


I am using the principle in a symphony project and I have a small problem.

I have a "character" unit and "device" unit.

The character can wear only 5 instruments on it. But he could buy some other equipment to put in his list. In this way, he could switch one of his tools to his list.

Then, in my "Character" unit I have:

  / ** * @ ORM \ ManyToMany (targetEntity = "RA / WelcomeBundle \ unit \ tool" Waterfall = {"continues"}) * @ORM \ JoinTable (name = "inventory.character") * / personal $ list; / ** * @ORM \ ManyToMany (targetEntity = "RA = WelcomeBundle unit \ tool", waterfall = {"continues"}) * @ORM \ JoinTable (name = "EquipmentWearCharacter") * / private $ equipementsWear;   

The problem is: I want to get the list of devices that the character does not already buy. In fact I want to get the list of tools that are in the complete list (findAll) in the tool but not in the list of character lists.

I try to make a request but do not know the principle of the table "Inventory Character" because there is no related unit class ... so I can not select "P select from inventory ..."

How can I do this? I want to specify to search in the actual database, not in the list of entity category ...

'Many' relations with principle are very transparent. You can not do more than get an entity list for one or the other.

If you ever find yourself in need of reaching the 'relation' table, to add additional data about the relationship (such as the time has been made) or to apply a filter (eg Recently created), you have to make that relationship yourself ie character inventory. And establishment of OneToMany and ManyToOne relationships among 3 entities

Hope this help

+++++++++++ edit ++++++++++++

you Simply buy (i.e. not bought yet) all devices can buy the user again, you really do not need to make middle unit character inventory:

  / ** * Add to unit * * @ORM \ ManyToMany (targetEntity = "rs \ WelcomeBundle \ entity \ Character"), cascade = {"persist"}) * @ORM \ JoinTable (name = "inventory tract") * / private $ letter;   

Then you can use it to query what you want:

  $ DQL = "Selection from RS \ WelcomeBundle \ unit \ Join the device in the left. Seritor whistle WHERE whistle! =: Character "; $ Found = $ em-> Security ($ dql) - & gt; SetParameter ('character', $ character antibiabetate) - & gt; GetResult ();    

No comments:

Post a Comment