Amit

I don't really think the declarations are wrong... but there can be
duplicate names in the Category model...

Here:

class Article extends AppModel {
  var $name = 'Article';
  var $hasMany = 'ArticleCategory';
}

class ArticleCategory extends AppModel {
  var $name = 'ArticleCategory';
  var $belongsTo = 'Article';
}

your solution of $this->Article->findAll('Category.name = "Category
One" OR Category.name = "Category Three"')  will find articles in
"Category One" OR articles in "Category Three". Not those that have
BOTH categories...

I'm starting to think that I might have to do it manually into the
model... =)

Also, if anyone has a solution that needs to change my database
scructure (something like habtm), i'm open to suggestions... the
project is not even into alpha yet.. =)

Thanks everyone
- Sergio

On Oct 22, 8:32 am, "Amit Badkas" <[EMAIL PROTECTED]> wrote:
> 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 cake-php@googlegroups.com
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