from product entity:

// ...
    
     /**
     * @ORM\ManyToMany(targetEntity="Sottocategoria", mappedBy="prodotti")
     * @ORM\JoinTable(name="sottocategorie_prodotto")
     * */
    private $sottocategorie;

    // ...

Il giorno giovedì 6 febbraio 2014 18:35:26 UTC+1, zarloc ha scritto:
>
> but I have to find the products that have the subcategory 1 and 3 
> simultaneously. 
>
> that the query should I use?
>
> Il giorno giovedì 6 febbraio 2014 18:25:07 UTC+1, Marco Pivetta ha scritto:
>>
>> Hi Zarloc,
>>
>> The first query will always produce no results:
>>
>> "SELECT p FROM Module\Entity\Product p JOIN p.subcategories s WHERE s.id=1 
>> AND 
>> s.id = 3"
>>
>> This is looking for a subcategory that has both ID 1 and 3 - that is 
>> obviously not possible.
>>
>> Cheers,
>>
>> Marco Pivetta 
>>
>> http://twitter.com/Ocramius      
>>
>> http://ocramius.github.com/
>>
>>
>> On 6 February 2014 18:10, zarloc <[email protected]> wrote:
>>
>>> Hi,
>>> i have this entity:
>>>
>>> Category----->---OneToMany--->Subcategory----->ManyToMany----->Product
>>>
>>> I have to find the products that have the subcategory 1 and 3
>>>
>>> Use the following query
>>>
>>> SELECT p FROM Module\Entity\Product p JOIN p.subcategories s WHERE s.id=1 
>>> AND 
>>> s.id = 3
>>>
>>> but I get 0 results.
>>>
>>> if i use the following query
>>>
>>> SELECT p FROM Module\Entity\Product p JOIN p.subcategories s WHERE s.idIN ( 
>>> 1, 3 )
>>>
>>> I find all the products you have 1 OR 3
>>>
>>> but I have to find products that have both 1 and 3
>>>
>>> where am I wrong?
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "doctrine-user" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/doctrine-user.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to