containable

Paginate results filtered by condition on associated model (HABTM) using Containable

橙三吉。 提交于 2019-12-08 03:04:07
问题 I need to paginate list of Product s belonging to specific Category (HABTM association). In my Product model I have var $actsAs = array('Containable'); var $hasAndBelongsToMany = array( 'Category' => array( 'joinTable' => 'products_categories' ) ); And in ProductsController $this->paginate = array( 'limit' => 20, 'order' => array('Product.name' => 'ASC'), 'contain' => array( 'Category' => array( 'conditions' => array( 'Category.id' => 3 ) ) ) ); $this->set('products', $this->paginate());

Paginate results filtered by condition on associated model (HABTM) using Containable

别等时光非礼了梦想. 提交于 2019-12-06 05:40:59
I need to paginate list of Product s belonging to specific Category (HABTM association). In my Product model I have var $actsAs = array('Containable'); var $hasAndBelongsToMany = array( 'Category' => array( 'joinTable' => 'products_categories' ) ); And in ProductsController $this->paginate = array( 'limit' => 20, 'order' => array('Product.name' => 'ASC'), 'contain' => array( 'Category' => array( 'conditions' => array( 'Category.id' => 3 ) ) ) ); $this->set('products', $this->paginate()); However, resulting SQL looks like this: SELECT COUNT(*) AS `count` FROM `products` AS `Product` WHERE 1 = 1

CakePHP containable conditions not limiting results?

徘徊边缘 提交于 2019-12-06 00:06:51
I'm trying to find a User's grocery items in a categorized list. The associations are Category hasMany Item hasMany User through Grocery. I'm using the Containable Behavior and it is not filtering out all other Grocery. It returns every item basically. My controller function: function showlist() { $categories = $this->Category->find('all', array( 'contain' => array( 'Item' => array( 'Grocery' => array( 'conditions' => array( 'Grocery.user_id =' => $this->Auth->user('id') ) ) ) ) )); Array that's returned: Array ( [0] => Array ( [Category] => Array ( [id] => 10 [parent_id] => [name] => Dairy

Adding conditions to Containable in CakePHP

六月ゝ 毕业季﹏ 提交于 2019-12-05 06:34:54
Previously I was relying on recursive, but I didn't get solution for some, then I found that Containable works fine for these. I am developing a movie review website. In that I need to show the list of movies which is related to a particular Genre. I have this below code: //example $genre = "drama"; $options = array( 'contain' => array( 'Movie', 'MoveiGenre.Genre' => array( 'conditions' => array('MovieGenre.Genre.name = "'.$genre.'"') ), 'MovieGenre.Genre.name' ), 'recursive' => 2, 'limit' => 10 ); $this->paginate = $options; $this->set('movies',$this->paginate()); The real problem starts here