symfony - Doctrine 2 manyToMany relation Selecting Entity with AND -


I am creating a website that needs the ability to filter villa based on their options. For example: A villa has options: Wi-Fi, pool, animal permissions

I am giving the option of filtering: Wi-Fi and the pool. Now a filtered list of villas based on these two options is required. Therefore I only want the villa to have both Wi-Fi and pool

My villa institution looks like this:

class object {/ ** * @var integer * * @ORM \ column (name = "id", type = "integer") * @ORM \ Id * @ORM = Generated Values ​​(strategy = "Auto") * / Private $ ID; / ** * Water String * * @ORM \ column (name = "name", type = "string", length = 255) * / private $ name; / ** * @ORM \ manyToMany (targetEntity = "Options", mapped = "objects") * / personal $ option; // ...}

and my options unit looks like this:

  class options {/ ** * @ integer * * @ORM \ Columns (name = "id", type = "integer") * @ORM \ Id * @ORM \ generated values ​​(strategy = "auto") * / private $ ID; / ** * @string string * * @ORM \ column (name = "name", type = "string", length = 255) * / private $ tag; / ** * @ORM \ manyToMany (targetEntity = "object", invoked by = "options") * @ORM \ JoinTable (name = "Object_Options") * / Private $ objects; // ...}  

I have an array of filter ID $ filters with which I need a filter

It does not seem to be understood how to complete it.

Now let me have this

  $ qb = $ this- & gt; GetEntityManager () - & gt; CreateQueryBuilder (); $ Qb- & gt; Select ("o") - & gt; From ("object", "o"); If ($ filter & amp; count ($ filter) & gt; 0) {$ qb- & gt; Internal join ("o.options", "f"); $ Qb- & gt; And where ($ fax - $ ft) in $ (- qb- & gt; expr) - & gt; } $ Query = $ qb- & gt; GetQuery ();  

But this is actually the opposite of what I need. It filters the villa based on the option but uses OR instead of AND. So it gives me results where the villas have Wi-Fi or pool.

Then I need it in a phishing code:

  Get all the objects, which have every given option (and probably more)  

Has anybody shed some light on this?

resolved :

OK, So I understood that I was on the right track with my code, but it needed a bit of salt, apparently after you have selected all the options, you have to check that The amount of filter is the same as the amount of filter given by you. What really came to mind when I stepped up my step in MySQL

$ qb = $ this-> GetEntityManager () - & gt; CreateQueryBuilder (); $ Qb- & gt; ("Object", "o") ("DISTINCT o") - & gt; Choose; If ($ filter & calculation ($ filter)> gt; {$ qb- & gt; Internal Join ("O.Points", "F", "with", "F.ID in (filter:") -> Setpalmator ("filter", $ filter); $ Qb- & gt; GroupBy (" $ Qb-> ("COUNT (DISTINCT f.id) =" count ") - & gt; Setpayeter (" calculation ", calculation ($ filter));}

Comments