Thanks i am trying the method on the first page..
In my controller items_controller.php I have this
$this->Items-
>bindModel(array('hasOne'=>array('CategoryItem'=>array())));
$constraint['CategoryItem.category_id'] = $category_id;
// or pass an array to genereate "IN (1,2,3..)" in the
sql.
$this->set('items',
$this->Post->findAll($constraint)
);
And my model looks like this
category_item.php
<?php
class CategoryItem extends AppModel {
var $name = 'CategoryItem';
}
?>
But it throws up an error
No Database table for model CategoryItem (expected "category_items"),
create it first.
So it looks like it does not make from category model categories in
the table? How should i name the model instead as category is
different then for example post which would only have an extra s at
the end. :(
On Feb 26, 1:37 pm, "AD7six" <[EMAIL PROTECTED]> wrote:
> On Feb 26, 1:22 pm, "Mech7" <[EMAIL PROTECTED]> wrote:
>
> > Hmm but i have a function to find all of them for the index and a
> > category function to find only those with the selected category? How
> > would i do this in the model?
>
> > On Feb 26, 2:06 am, "Grant Cox" <[EMAIL PROTECTED]> wrote:
>
> > > Afaik you cannot query across a hasMany association, as these are
> > > built with extra queries rather than a join (like belongsTo uses).
>
> > > Instead, do the query on the Category model, and from that result get
> > > the associated Items that are loaded.
>
> As google group's search seems a bit fogetful, have a look at this:
>
> http://www.google.com/search?q=groups+cakephp+%22Filtering+habtm%22
>
> HTH,
>
> AD
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---