Questions tagged [containable]

Containable is a core CakePHP behaviour for filtering and limiting model find queries.

Containable is a core CakePHP behaviour for filtering and limiting model find queries. It works by binding and unbinding models on the fly, and results in a filtered, efficient result set that can cut down on memory and database resources.

View the official documentation on the Containable behaviour.

117 questions
7
votes
1 answer

Adding conditions to Containable in CakePHP

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…
5
votes
2 answers

CakePHP - Is it possible to use Containable behaviour with the read() method?

I'm new with CakePHP and can't figure out how to call the read() method of a model class with a Containable behaviour. I can do the following with find() $this->T->find('all', array ( 'contain' => array ( 'C', 'L' => array ( …
Gustavo
  • 195
  • 2
  • 11
5
votes
5 answers

How can I minimize the 'contain' queries in CakePHP?

I have three models, Users, Comments and Pages. Users has many Comments, and Comments belong to Pages. All models use the containable behavior, and default to recursive -1. If I call a find() query on Comments, with the contain request including…
Rhys
  • 1,581
  • 2
  • 14
  • 22
4
votes
1 answer

Cakephp - contain (containable behavior) fetches too much

As I understood from the cakephp-documentation, one of the advantages of the 'containable'-Behavior is being able to fetch fewer data if you need fewer data... But that doesn't seem to work in my case of a connection between users and usergroups. My…
jwulf
  • 169
  • 1
  • 9
4
votes
2 answers

When not to use Containable Behavior in CakePhp 2.x

After a few times adding Containable Behavior to my various model classes, I have a good mind to simply chuck the line into AppModel instead and thus make every model Containable. Which then makes me wonder, is there any situation where it is not…
medcatt
  • 67
  • 7
3
votes
3 answers

CakePHP Contains not working with Recursive

When I try: // Removed the limit to ensure that all of the group notes items can be found and collapsed $recent_notes = $this->User->Note->find('all', array( 'recursive' => 2, 'order' => 'Note.created DESC', 'conditions' => $conditions, …
Garrett
  • 11,451
  • 19
  • 85
  • 126
3
votes
1 answer

CakePHP - find conditions with associations

I have an issue with a cakePHP find conditions. I have a Club model, a User model and a Post model : Club hasMany Post Club HABTM User Basically, my clubs_users table also contains additional fields such as let's say 'limit' and 'diff' that…
G.J
  • 795
  • 1
  • 6
  • 12
3
votes
2 answers

cakephp paginator extremely slow

I have a cakephp application, 2.4, and I'm having issues with the Paginator component. First off, it's not the database, it's definitely the execution of parsing the query results. I have DebugKit installed and can see that my mysql query for the…
mneil
  • 148
  • 7
3
votes
1 answer

CakePHP: If I combine 'fields' and 'contain' in find I don't get the desired result. Can anyone explain why?

I have the following situation: A work has a Image which belongs to a ImageGroup. If I do this: $works = $this->Work->find('all', array( 'contain' => array( 'PreviewImage' => array( 'fields' => array('PreviewImage.id',…
Andreas Daoutis
  • 1,195
  • 8
  • 16
3
votes
2 answers

CakePHP containable conditions not limiting results?

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…
Chris
  • 644
  • 1
  • 12
  • 28
3
votes
1 answer

CakePHP plugin models not associating when using Containable

I have a CakePHP plugin named Foo that has a component, no controller, and several joined models. It's structured like this: /Plugin/Foo/Model/ -FooModel1.php -FooModel2.php -FooModel3.php -FooModel4.php In order to connect with the standard…
user1449855
  • 1,195
  • 2
  • 10
  • 14
2
votes
2 answers

Pagination with Containable conditions work with hasOne, but not with hasMany

For example, I have this relationship: UserContact hasMany Contact Contact hasOne Info Contact hasMany Response And I need to paginate Contact, so I use Containable: $this->paginate = array( 'limit'=>50, 'page'=>$page, …
Nick Zinger
  • 1,174
  • 1
  • 12
  • 28
2
votes
2 answers

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

I need to paginate list of Products belonging to specific Category (HABTM association). In my Product model I have var $actsAs = array('Containable'); var $hasAndBelongsToMany = array( 'Category' => array( 'joinTable' =>…
lxa
  • 3,234
  • 2
  • 30
  • 31
2
votes
2 answers

CakePHP: Select DISTINCT in ContainableBehaviour

I am trying to select only distinct related model entries but it seems it doesn't work. I have this: $active_questions = $this->Question->find('all', array('conditions' => array('test_id' => $active_tests), 'fields' => array('answer_style_id'),…
linkyndy
  • 17,038
  • 20
  • 114
  • 194
2
votes
1 answer

Getting CakePHP's searchable behavior results to contain deeper associations

I am trying to use CakePHP 1.3.5's searchable behavior with containable behavior to return search results for a specified model and an associated model (Article belongsTo User). Ignoring the searchable behavior for a moment, the following call to…
Phantom Watson
  • 2,667
  • 4
  • 25
  • 39
1
2 3 4 5 6 7 8