containable

CakePHP find with “contain”

十年热恋 提交于 2020-01-07 05:28:19
问题 My model has many relationships to other tables/models, if i use contain parameter, for example to order by field in results of one model, all other tables in query results are missing, and must manually written in contain parameter, how can i get all related models data without manually writing it? $data = $this->Cv->find('first', array( 'contain' => array('Cv_experience' => array('order' => 'Cv_experience.start_year desc')))); 回答1: It sounds like you've been relying on the Model's recursive

Containable won't filter 2nd level model with HABTM & hasMany

余生颓废 提交于 2020-01-06 14:35:37
问题 What I have: "A" HABTM "C" HABTM "A" through join table "B" "A" hasMany "B" belongsTo "A" "C" is ordered by a "B" field What I want: // result: [0] => array( A => array( /* single model's fields I still need*/ ), C => array( [0] => array( C.field1, C.field2, ... /* Model C fields*/ ), [1] => array( C.field1, C.field2, ... ) ) ) What I've tried: // this gives me data I don't need: A->find('all', array( 'conditions' => array( 'id' => $id ) ) ) // result: [0] => array( A => array( /* single

CakePHP Containable with HABTM

若如初见. 提交于 2019-12-24 02:42:48
问题 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 models: Course (belongs to "Teacher", hasAndBelongsToMany "Student") Student (hasAndBelongsToMany "Course") Teacher (hasMany "Course") Now let's say I want to see a list of all of the unapproved sign-ups that are for ninth-graders. That's easy:

When not to use Containable Behavior in CakePhp 2.x

不想你离开。 提交于 2019-12-23 15:29:13
问题 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 desirable or counterproductive for a particular model to have Containable Behavior? 回答1: I would say too few to be worried about. I put containable in App Model: class AppModel extends Model { public $recursive = -1; public $actsAs = array(

Cakephp - contain (containable behavior) fetches too much

旧城冷巷雨未停 提交于 2019-12-23 12:17:18
问题 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 associations look like: Group hasMany: Membership User hasMany: Membership Membership belongsTo: User, Group (I'm not using HABTM, instead use the Model 'Membership' in between to join users and groups). All Models implement the 'Containable'

Containable to do show deeper data or join table

橙三吉。 提交于 2019-12-13 04:37:51
问题 I have 3 tables: projects, project_reminder_users, project_types. The relations is as follow: Project => belong to => ProjectType hasMany => ProjectReminderUser ProjectReminderUser => belong to => Project ProjectType => hasMany => Project I get all data based on who assigned(ProjectReminderUser) by this $this->Project->ProjectReminderUser->Behaviors->load('Containable'); $this->paginate = array( 'ProjectReminderUser' => array( 'limit' => $limit, 'contain' => array( 'Project' => array(

Cakephp find all query on multiple models

依然范特西╮ 提交于 2019-12-12 18:15:13
问题 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 return an empty value for MenuItem when not 7. How can I accomplish that it'll only load the articles from MenuItem 7? MenuItem has a HABTM relationship with Article code: $d=$this->Article->find('all' , array('contain' => array( 'MenuItem' =>

CakePHP 1.3 contain not building associations correctly

烂漫一生 提交于 2019-12-11 08:58:30
问题 this is my first question here. I'm having an issue with containable behavior in cakephp 1.3. The issue is as follows: I have a Deliverable model with the following associations: class Deliverable extends AppModel { var $name = 'Deliverable'; var $displayField = 'name'; var $actsAs = array('Containable'); var $belongsTo = array( 'Asset' => array( 'className' => 'Asset', 'foreignKey' => 'asset_id', 'dependent' => false ), 'DelRouteName' => array( 'className' => 'DelRouteName', 'foreignKey' =>

CakePHP containable conditions not limiting results?

喜你入骨 提交于 2019-12-10 10:19:59
问题 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

Adding conditions to Containable in CakePHP

旧街凉风 提交于 2019-12-10 04:37:00
问题 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' =>