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
2
votes
0 answers

CakePHP counterCache with contain

i have the following database structure: Users id, username, ..., silver_medal_counter, gold_medal_counter, bronze_medal_counter Badges id, name, description, points, medal (silver, gold, bronze) Userbadges id, user_id, badge_id, created If a…
q0re
  • 1,401
  • 19
  • 32
2
votes
2 answers

CakePHP 2.x containable + pagination for nested model

I have a problem with nested model pagination using containable in Cake... I've got three models: Category, CompanyCategory, Company and there association is like this Category hasMany CompanyCategory CompanyCategory belongsTo Category…
kris
  • 23
  • 1
  • 5
2
votes
5 answers

CakePHP order query results on more than 1 level

I'm using the Containable behavior to get a list of Comments (belongsTo Post, which belongs to Question; Question hasMany Post, and Post hasMany Comments; all of these belong to Users). $data = $this->Question->find ( 'first', array ('contain'…
atp
  • 30,132
  • 47
  • 125
  • 187
2
votes
2 answers

Excluding hasMany models in CakePHP

Here's my basic setup... Families hasMany Students hasMany Enrollment Is there a way to exclude a student if enrollment is empty? Here is my find method. $options = array( 'order' => array('Family.family_last_name'), 'group' =>…
Randy Gonzalez
  • 445
  • 5
  • 17
2
votes
1 answer

CakePHP Containable with HABTM

To explain the issue I'm having, I'll use an example. Let's say that I'm building a system where students can sign up for one or more afterschool courses, but a school official has to approve the sign-up in order for it to be valid. So I have these…
Nick
  • 8,049
  • 18
  • 63
  • 107
2
votes
1 answer

Cakephp find all query on multiple models

I try the following to get al the Articles That belong to MenuItem 6 and have an Article content_type of 'blog'. It does find all the articles with content_type='blog'. But I only want it to return the Article if it belongs to Menuitem 7. And now it…
waterschaats
  • 994
  • 3
  • 18
  • 32
2
votes
2 answers

Containable Nested models

I have a few nested models which I'm trying to load using Containable behaviour in CakePHP. Most of it works fine. However, 1 model that has a hasMany relation only returns 1 object: $article = $this->News->find('first',array( …
Bart Vangeneugden
  • 3,436
  • 4
  • 33
  • 52
2
votes
3 answers

CakePHP containable order condition not working

I'm having problems with a very simple ordering query. I have a Post model and a Tag model with a HABTM relationship and am trying to return a list of all posts with a particular tag assigned to them, ordered by the date the post is…
Loftx
  • 1,760
  • 4
  • 29
  • 50
2
votes
2 answers

CakePHP: ContainableBehavior Query Structure/Joins

My Application's Data Model Group hasMany User User belongsTo Group User hasMany Punch Punch belongsTo User Punch belongsTo PayPeriod PayPeriod hasMany Punch Find call $groups = $this->Group->find('all', array( 'contain' => array( 'User' =>…
1
vote
2 answers

CakePHP -- limiting results from one model to those with matching conditions in an associated model

I'm just getting started in CakePHP, and am running into trouble limiting retrieved results to those where a field in an associated model matches a certain value. I've found a lot of related questions here and elsewhere, but they seem to deal with…
cmw
  • 855
  • 7
  • 17
1
vote
3 answers

CakePHP Containable doesn't fire other behaviors' callbacks on contained models?

Nobody seems to have a problem with that so either I'm doing it wrong or no one ever tried: I have a model "Infocenter" which has many "InfocenterArticle"s. To fetch data including the related stuff I attached the Containable behavior to both. This…
Rekhyt
  • 76
  • 5
1
vote
1 answer

Filtering Containable Model Results

I am trying with the following line of code to filter all the Posts that have certain (irrelevant) conditions, by the tag "who" $com= $this->Post->find('all', array('conditions' => $conditions, 'contain' => 'Tag.tag="who"')); However, instead of the…
user794486
  • 31
  • 2
1
vote
3 answers

CakePHP containable and paginate - deep associations not appearing

I'm trying to use containable in a paginated query. The code is below, in full. $this->paginate = array( 'conditions'=>array( 'Track.pending'=>0, 'Track.status'=>1 ), 'contain'=>array( …
Will
  • 1,893
  • 4
  • 29
  • 42
1
vote
1 answer

CakePHP JSON API containable question

right now I have controllers/actions that do standard retrieval of model/associated model data. My actions currently just pass the variables to the views to pick and choose which values to display to the user via HTML. I want to extend and reuse…
pll
  • 297
  • 1
  • 5
  • 15
1
vote
1 answer

Ordering by number of hasMany records - COUNT(RelatedModel.field)

I have a model, Track, that hasMany Vote. the Vote model has a field called "value". What I wish to do is to sort Track records by the sum of the values of their votes (which means unfortunately I can't use counterCache). Of course, trying to put…
Will
  • 1,893
  • 4
  • 29
  • 42