On 10/22/07, LS <[EMAIL PROTECTED]> wrote:
>
>
> Hello everyone!
> I promise I tried searching for this in this group and other sql-
> related groups... Maybe I just haven't searched for the right thing...
> Or even, maybe my head is not working properly...
>
> Here's the thing: I have 2 tables. One with articles and one with
> categories... It goes like this (i used the model names):
>
> Article (id, date, name, description)
> ArticleCategory (id, article_id, name)
>
> ids are integer, date is datetime, names are varchar and description
> is text.
>
> So, I have many articles with "n" categories each. And I want to grab
> all the articles that are from "Category One" _and_ "Category
> Three" (just an example, ofcourse).
> I just couldn't find a suitable query to retrieve that... I'm starting
> to wonder if it is even possible to do it using only one query...
>
> Any help is appreciated... Thanks in advance!
> - Sergio
>

- I think you are defining model relations incorrectly here. The correct
relations may be category hasMany articles and article belongsTo category
The categories table will have id, name and the articles table will have id,
date, name, description, category_id. Now to find articles in two
categories, $this->Article->findAll('Category.name = "Category One" OR
Category.name = "Category Three"') will work

-- 
Regards,
Amit

http://amitrb.wordpress.com/
http://coppermine-gallery.net/
http://cheesecake-photoblog.org/
http://www.sanisoft.com/blog/author/amitbadkas

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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