Tuesday, March 10, 2015

Re: Condition with AND and ARRAY

But worked with IN and it don't made the search correctly. 

When I click in filter tag it shows me all products with tags selected, and not the products with the combined tags.

Example: 

Product 1 - tags: mom - child - birthday
Product 2 - tags: mom - adult - party
Product 3 - tags: mom - child - party

If I select the tags mom and child, it shows me all products, when should show me only products 1 and 3. 

Em segunda-feira, 9 de março de 2015 18:37:11 UTC-3, José Lorenzo escreveu:
If you execute the SQL above you will always get 0 results.

I think that what cake does by default (using IN) is exactly the thing you want, based on what you described (your hesitance on using UNION queries to get all results)

On Monday, March 9, 2015 at 8:54:09 PM UTC+1, michel martins wrote:
I need for all products that have tag_id = array item

SELECT * FROM produtos AS Produtos LEFT JOIN tags_produtos as TagsProdutos ON Produtos.id = TagsProdutos.produto_id  WHERE TagsProdutos.tag_id = 730 AND TagsProdutos.tag_id = 731 AND TagsProdutos.tag_id = 735

I have doubts whether I do the sql above or use UNION between multiple queries.

Table PRODUTOS
ID - PRODUTO

Table TAGS_PRODUTOS
ID - PRODUTO_ID - TAG_ID 

Table TAGS
ID - NAME

$tags = array('0'=>'730', '1'=>'731', '2'=>'735')

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: