CakePHP: multi-deep model queries
I have the following models:
Book -> hasOne(Subcategory) -> belongsTo(Category)
I have to make the following query:
select c.ds_category,count(*) from categories c,subcategories sc,books b
where b.id_subcategory=sc.id_subcategory and sc.id_category=c.id_category
group by c.ds_category
In the Book model I've defined
var $hasOne="Subcategory";
In the subcategories model I've defined
var $belongsTo="Category";
The problem is that when I call
return $this-&g开发者_高级运维t;find("all");
I cannot get categories table so cannot make group by.
Ive tried to define $recursive=2
but I did not run.
Can anyone help me in finding a way to get also Categories items?
shouldn't Book belongsTo Subcategory? And you should use Containable to have a more control over find.
精彩评论