Hi Amit, thank you for your answer. Your query makes sense to me, but
how do I use that in a cakephp controller/model?

I should probably mention I have a few years experience with PHP but
this is my first MVC framework experience. From the tutorials I am
supposed to use someting like $this->Model->find() .. should I use
$this->Model->query() inside the controller?


Thanks!


On Dec 21, 12:15 am, Amit Badkas <[email protected]> wrote:
> Hi,
>
> Try to build the SQL query something like
>
> SELECT *, COUNT(DISTINCT tags.name) AS uniques FROM products, products_tags,
> tags WHERE products.id = products_tags.product_id AND tags.id =
> products_tags.tag_id AND tags.name IN ('ruby', 'earrings') GROUP BY
> products_tags.photo_id HAVING uniques = 2
>
> Please feel free to change the table and field names as per your need but
> have a look at the use of 'uniques'. We used 2 for its value for HAVING as
> the number of tags to use are 2 ('ruby' and 'earrings').
>
> Hope this helps.
>
> Amit Badkas
>
> PHP Applications for E-Biz:http://www.sanisoft.com
>
>
>
>
>
>
>
> On Tue, Dec 21, 2010 at 1:43 AM, halfasleeps <[email protected]> wrote:
>
> > If I want to create a category and be able to link products to it by
> > tags I can like so:
>
> >  - Create the category and product tables.
> >  - Create a tags table with tags like: Ruby, Earrings, White-Gold
> >  - Create a category_tags and product_tags table to map them
> >  - Set category and product to hasAndBelongsToMany tags
> >  - Set tags to hasAndBelongsToMany products and hasAndBelongsToMany
> > categories
> >  - Now say I have 2 products one with tags: Ruby and Earrings and
> > another with tags: Ruby and Bracelet
>
> > Say I want to create a "Ruby Earrings" category.
>
> > I could add the Ruby and Earrings tags to the category. But under
> > normal HABTM Model associations both products will be returned because
> > even though only 1 has an earrings tag they both have a ruby tag.
>
> > How can I make it only match products that have ALL of the same tags
> > as the category (products can have more tags but must have all the
> > tags the corresponding category has) in order be returned?
>
> > Also, taking that even further, how could I add -tags to a category
> > that the products must NOT have these tags to be returned?
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]<cake-php%[email protected] 
> > om>For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to