Problems with relationships without Auto increment
I have the following relationships Contact HABTM List list HABTM Contact Only I had to take my auto_increment primaryKey ID field from the contact table, I'm having problem when using INSERT IGNORE. To replace the auto_incremente created the following trigger: DECLARE AUTOI int UNSIGNED DEFAULT 0; SELECT max(id) into AUTOI from contacts; IF (AUTOI IS NULL) THEN SET new.id=1; ELSE SET new.id=AUTOI+1; END IF; When I save a new record in the table contacts is all right, more on the table contacts_lists the field contat_id is always with value 0 Would anyone know tell me how can I fix this? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
cakePhp - create drop down list with belongsTo association relationships
May i get some examples on create a drop down list with belongsTo relationship? the option that will be show in the drop down list should be retrieve from database table. I hardly can't find any examples on this in the internet. please help. thanks in advance. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: cakePhp - create drop down list with belongsTo association relationships
For example's sake, lets say that you have User and then UserType, user types consists of the following records: Admin, Editor, Contributor, User You want to have a drop down list with all the user types, so when creating a new user you can select which type it should be (in this example), you would do something like this. *Controller (basic):* $this-set('userTypes', $this-User-UserType-find('list')); *View (form):* echo $this-Form-input('User.user_type_id', array('options' = $userTypes)); If you name your field and variable correctly, CakePHP should automatically pick up that $userTypes holds the options for the 'User.user_type_id' field. Here is more on it: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs On 6 July 2014 08:07, Tze Pin tpin0...@gmail.com wrote: May i get some examples on create a drop down list with belongsTo relationship? the option that will be show in the drop down list should be retrieve from database table. I hardly can't find any examples on this in the internet. please help. thanks in advance. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout. -- Kind Regards Stephen Speakman -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Is nested one-to-many table relationships possible in CakePHP?
The short answer is Yes as CakePHP supports nearly whatever relationships you design in your database. You relationships are as this: Table1 - hasMany - Table2 - hasMany - Table3 With CakePHP you can find data from Table1 alone, from Table1 including Table2, and also from Table1 including Table2 including Table3 - as your data is related. Suggest you to take a look at the Model and the ModelHelper Contains in the CakePHP book/documentation. Enjoy, John On Friday, 6 September 2013 05:13:37 UTC+3, Sam wrote: Dear CakePHP experts, While designing a database structure, I created 3 tables. There is a 1-to-many relationship between the first table and second table. There is another 1-to-many relationship between the second table and third table. Does CakePHP allow this kind of table relationship? I hope this does not sound like a stupid question to the experts here. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Is nested one-to-many table relationships possible in CakePHP?
Correction to this part: Suggest you to take a look at the Model and the ModelHelper Contains in the CakePHP book/documentation. Should be: Suggest you to take a look at the Model and the Behaviour Containable in the CakePHP book/documentation. Enjoy, John -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Is nested one-to-many table relationships possible in CakePHP?
Dear CakePHP experts, While designing a database structure, I created 3 tables. There is a 1-to-many relationship between the first table and second table. There is another 1-to-many relationship between the second table and third table. Does CakePHP allow this kind of table relationship? I hope this does not sound like a stupid question to the experts here. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Is nested one-to-many table relationships possible in CakePHP?
class FirstModel extends AppModel { public $hasOne = array('Second'); public $hasMany = array('Third'); } class SecondModel extend AppModel { public $belongsTo = array('First'); } class ThirdModel extend AppModel { public $belongsTo = array('First'); } On Fri, Sep 6, 2013 at 10:13 AM, Sam lightai...@gmail.com wrote: Dear CakePHP experts, While designing a database structure, I created 3 tables. There is a 1-to-many relationship between the first table and second table. There is another 1-to-many relationship between the second table and third table. Does CakePHP allow this kind of table relationship? I hope this does not sound like a stupid question to the experts here. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out. -- Simon Males -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
CakePHP - how should I do these relationships and name my tables?
It's a song and lyrics database. I'm trying to bake an app from my database, which looks like this: (every table does have a primary key 'id', I just left them out..) songs song_name artists artist_name songs_singers artist_id (FOREIGN KEY artists.id) song_id (FOREIGN KEY songs.id) songs_writers artist_id (FOREIGN KEY artists.id) song_id (FOREIGN KEY songs.id) song_views song_id (FOREIGN KEY songs.id) videos song_id (FOREIGN KEY songs.id) video_views video_id (FOREIGN KEY videos.id) Writers and singers both overlap, i.e. some writers sing and some singers write. When I bake the songs table, I get this error: * Error: Table singers for model Singer was not found in datasource default.* I think the problem is that CakePHP wants me to create a new model for singers, so I'll have to end up duplicating the names of writers and singers in a new table singers. I just want the names stored in artists and have both song_singers and song_writers link to that table with foreign key IDs. songs have many: * views * videos videos have many: * views both writers and singers have many: * songs What should I do? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: queries on HABTM relationships
On Wed, Jan 2, 2013 at 8:32 PM, Stefano Campanella leona...@guildofmessengers.com wrote: Yes I am sure. In my case id is not numeric, the permission name is already an identifier for the permission Your DB schema is broken by design, then. Good luck with that. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
Broken for CakePHP or broken in general? Generally, I would not see a problem in using a non-numeric primary key, you just have to be conscious of the constraints this imposes. If it is for a constraint of CakePHP, well I didn't experience any problem with that yet. There is no error in queries. And permissions would be used as a read-only model, so no problem with the absence of auto-increment. AnywayI moved the permission entities out the db, they just didn't make sense there since they are never going to change during the life of the website. On Thursday, January 3, 2013 8:03:24 PM UTC+1, cricket wrote: On Wed, Jan 2, 2013 at 8:32 PM, Stefano Campanella leon...@guildofmessengers.com javascript: wrote: Yes I am sure. In my case id is not numeric, the permission name is already an identifier for the permission Your DB schema is broken by design, then. Good luck with that. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
Yes I did, but it does not suit my needs or my organization structure. For me it's at the same time too complicated and too limited. I don't need a tree, I need a graph, where a user can have more than one group; because users can be categorized in more than one way. Anyway, do you have any idea of why the query is not executed correctly? From the CakePHP Book I got the impression that that was the correct way to make that kind of search. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
When running a find('count') the contain param is useless. This is because the main query is fetching a sum, not a set of records from which to fetch the associated 'contain' records. Are you using AuthComponent? You can use that to fetch the User and associated records. However, I can't remember how deep it goes. To see what records it has, put this in your UsersController login method: die(debug($this-Auth-user())); http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user On Tue, Jan 1, 2013 at 5:23 PM, Stefano Campanella leona...@guildofmessengers.com wrote: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
mmh, ok. But the problem is that even if I change the find(count) into a find(all) it still loads data only from Group table. Yes I am using the AuthComponent for logged in users. But since I want to use my Authorize class also for managing what anonymous users can access I am calling $this-Auth-isAuthorized() in the beforeFilter of AppController with a $user parameter of array('id'=0). Inside the authorize method I recognize the empty user and make checks for permissions on an hard coded group id. I checked this would work correctly, if only I could make the query in the right way. Let's change the question. Which code would you write to make CakePHP execute this query: SELECT COUNT(*) AS count FROM groups INNER JOIN groups_perms ON groups.id=groups_perms.group_id INNER JOIN perm ON groups_perms.perm_id=perm.id WHERE group.id=1 AND perm.id='can_access_admin' given that you have access to $this-controller()-Group? Thanks On Wednesday, January 2, 2013 7:59:24 PM UTC+1, cricket wrote: When running a find('count') the contain param is useless. This is because the main query is fetching a sum, not a set of records from which to fetch the associated 'contain' records. Are you using AuthComponent? You can use that to fetch the User and associated records. However, I can't remember how deep it goes. To see what records it has, put this in your UsersController login method: die(debug($this-Auth-user())); http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user On Tue, Jan 1, 2013 at 5:23 PM, Stefano Campanella leon...@guildofmessengers.com javascript: wrote: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake...@googlegroups.comjavascript:. To unsubscribe from this group, send email to cake-php+u...@googlegroups.com javascript:. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
This simply is solvable with: $this-Auth-userScope = array('User.can_access_admin' = 1); Put that in you beforeFilter function inside AppController, and your problems are solved. If you want to redirect them, than you shoukd do something like this: if ($this-Auth-user()) { if(isset($this-params['admin']) $this-Auth-user('admin') != 1) { $this-redirect('/'); } } Hope this helps. Cheers On Wed, Jan 2, 2013 at 7:59 PM, lowpass zijn.digi...@gmail.com wrote: When running a find('count') the contain param is useless. This is because the main query is fetching a sum, not a set of records from which to fetch the associated 'contain' records. Are you using AuthComponent? You can use that to fetch the User and associated records. However, I can't remember how deep it goes. To see what records it has, put this in your UsersController login method: die(debug($this-Auth-user())); http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user On Tue, Jan 1, 2013 at 5:23 PM, Stefano Campanella leona...@guildofmessengers.com wrote: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- *Ivan Rimac*** mail: ivn...@gmail.com *tel: +385 95 555 99 66* *http://ivanrimac.com* -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
Excuse me Ivan, but there is no reference to userScope attribute anywhere in the source code of cakePHP, I assume you mean $this-Auth-scope. But it still doesn't help me, is was under the impression that that attribute is used to impose conditions for logging users in, this is not my case, I am working on the Authorization not on the Authentication. Furthermore, can_access_admin is not a field of User and the scope attribute is considered only by the Authentication component not by the Authorization one as far as I know. Thank you anyway :) Il 02/01/2013 21.56, Ivan Rimac ha scritto: This simply is solvable with: $this-Auth-userScope = array('User.can_access_admin' = 1); Put that in you beforeFilter function inside AppController, and your problems are solved. If you want to redirect them, than you shoukd do something like this: if ($this-Auth-user()) { if(isset($this-params['admin']) $this-Auth-user('admin') != 1) { $this-redirect('/'); } } Hope this helps. Cheers On Wed, Jan 2, 2013 at 7:59 PM, lowpass zijn.digi...@gmail.com mailto:zijn.digi...@gmail.com wrote: When running a find('count') the contain param is useless. This is because the main query is fetching a sum, not a set of records from which to fetch the associated 'contain' records. Are you using AuthComponent? You can use that to fetch the User and associated records. However, I can't remember how deep it goes. To see what records it has, put this in your UsersController login method: die(debug($this-Auth-user())); http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user On Tue, Jan 1, 2013 at 5:23 PM, Stefano Campanella leona...@guildofmessengers.com mailto:leona...@guildofmessengers.com wrote: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com mailto:cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com mailto:cake-php%2bunsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com mailto:cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com mailto:cake-php%2bunsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- *Ivan Rimac* mail: ivn...@gmail.com mailto:ivn...@gmail.com /tel: +385 95 555 99 66/ /http://ivanrimac.com/ -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook
Re: queries on HABTM relationships
I think that should be something like: $data = $this-controller()-Group-find( 'count', array( 'conditions' = array( 'Group.id' = 1 // hard-coded for testing? ), 'joins' = array( array( 'type' = 'INNER', 'table' = 'groups_perms', 'alias' = 'GroupPerm', 'conditions' = array( 'GroupPerm.group_id' = 'Group.id' ) ), array( 'type' = 'INNER', 'table' = 'perms', 'alias' = 'Perm', 'conditions' = array( 'GroupPerm.perm_id' = 'Perm.id' ) ) ) ) ); However, I've left out the perm.id='can_access_admin' part because it makes no sense in the context of Cake. The id column should be an INT. I presume you mean something like 'Perm.type' = 'can_access_admin', in which case add it to the 2nd joins conditions array. On Wed, Jan 2, 2013 at 3:48 PM, Stefano Campanella leona...@guildofmessengers.com wrote: mmh, ok. But the problem is that even if I change the find(count) into a find(all) it still loads data only from Group table. Yes I am using the AuthComponent for logged in users. But since I want to use my Authorize class also for managing what anonymous users can access I am calling $this-Auth-isAuthorized() in the beforeFilter of AppController with a $user parameter of array('id'=0). Inside the authorize method I recognize the empty user and make checks for permissions on an hard coded group id. I checked this would work correctly, if only I could make the query in the right way. Let's change the question. Which code would you write to make CakePHP execute this query: SELECT COUNT(*) AS count FROM groups INNER JOIN groups_perms ON groups.id=groups_perms.group_id INNER JOIN perm ON groups_perms.perm_id=perm.id WHERE group.id=1 AND perm.id='can_access_admin' given that you have access to $this-controller()-Group? Thanks On Wednesday, January 2, 2013 7:59:24 PM UTC+1, cricket wrote: When running a find('count') the contain param is useless. This is because the main query is fetching a sum, not a set of records from which to fetch the associated 'contain' records. Are you using AuthComponent? You can use that to fetch the User and associated records. However, I can't remember how deep it goes. To see what records it has, put this in your UsersController login method: die(debug($this-Auth-user())); http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user On Tue, Jan 1, 2013 at 5:23 PM, Stefano Campanella leon...@guildofmessengers.com wrote: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake...@googlegroups.com. To unsubscribe from this group, send email to cake-php+u...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups
Re: queries on HABTM relationships
I just realised that this also makes no sense. Why are you running a COUNT(*) on Group when your condition is to select only the Group with id = 1? Perhaps you need to start from the beginning and explain what it is you're looking for. And I'll second the suggestion to use ACL. On Wed, Jan 2, 2013 at 5:50 PM, lowpass zijn.digi...@gmail.com wrote: I think that should be something like: $data = $this-controller()-Group-find( 'count', array( 'conditions' = array( 'Group.id' = 1 // hard-coded for testing? ), 'joins' = array( array( 'type' = 'INNER', 'table' = 'groups_perms', 'alias' = 'GroupPerm', 'conditions' = array( 'GroupPerm.group_id' = 'Group.id' ) ), array( 'type' = 'INNER', 'table' = 'perms', 'alias' = 'Perm', 'conditions' = array( 'GroupPerm.perm_id' = 'Perm.id' ) ) ) ) ); However, I've left out the perm.id='can_access_admin' part because it makes no sense in the context of Cake. The id column should be an INT. I presume you mean something like 'Perm.type' = 'can_access_admin', in which case add it to the 2nd joins conditions array. On Wed, Jan 2, 2013 at 3:48 PM, Stefano Campanella leona...@guildofmessengers.com wrote: mmh, ok. But the problem is that even if I change the find(count) into a find(all) it still loads data only from Group table. Yes I am using the AuthComponent for logged in users. But since I want to use my Authorize class also for managing what anonymous users can access I am calling $this-Auth-isAuthorized() in the beforeFilter of AppController with a $user parameter of array('id'=0). Inside the authorize method I recognize the empty user and make checks for permissions on an hard coded group id. I checked this would work correctly, if only I could make the query in the right way. Let's change the question. Which code would you write to make CakePHP execute this query: SELECT COUNT(*) AS count FROM groups INNER JOIN groups_perms ON groups.id=groups_perms.group_id INNER JOIN perm ON groups_perms.perm_id=perm.id WHERE group.id=1 AND perm.id='can_access_admin' given that you have access to $this-controller()-Group? Thanks On Wednesday, January 2, 2013 7:59:24 PM UTC+1, cricket wrote: When running a find('count') the contain param is useless. This is because the main query is fetching a sum, not a set of records from which to fetch the associated 'contain' records. Are you using AuthComponent? You can use that to fetch the User and associated records. However, I can't remember how deep it goes. To see what records it has, put this in your UsersController login method: die(debug($this-Auth-user())); http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user On Tue, Jan 1, 2013 at 5:23 PM, Stefano Campanella leon...@guildofmessengers.com wrote: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group,
Re: queries on HABTM relationships
Works like a charm! Thank you so much cricket! Now to reply to your questions: I am using a count because I don't need any content returned. With this query I just check if the record exists, if it does then I know the Group has the specified permission. The count will always return 0 if group 1 has no can_access permission or 1 if the group has the permission. I don't need any information, I only need to know if it exists. I didn't find any note about CakePHP supporting only integer ids, is this true? Every permission has a unique name and it is not going to change, so I thought using an integer id and another name field is useless, I just use the permission name as primary key. As for using ACL: reading CakePHP2.x Book I understood that ACL only supports trees structures, but it is a limitation for me because I need to be able to group my users in mode than one way. A user could be a Manager but also a Moderator, and these two groups are not one child of the other. I would need ACL to support more than just trees, it should support graphs. So I decided to make my Authorization component, which just uses flat groups (there is no group hierarchy) but allows one user to have more than one group. And it isn't even very big, the Authorize class is only 70 lines long, while ACL seems really too complex. Anyway, I am done now. Thank you to everyone who tried to help me!! On Wednesday, January 2, 2013 11:53:44 PM UTC+1, cricket wrote: I just realised that this also makes no sense. Why are you running a COUNT(*) on Group when your condition is to select only the Group with id = 1? Perhaps you need to start from the beginning and explain what it is you're looking for. And I'll second the suggestion to use ACL. On Wed, Jan 2, 2013 at 5:50 PM, lowpass zijn.d...@gmail.com javascript: wrote: I think that should be something like: $data = $this-controller()-Group-find( 'count', array( 'conditions' = array( 'Group.id' = 1 // hard-coded for testing? ), 'joins' = array( array( 'type' = 'INNER', 'table' = 'groups_perms', 'alias' = 'GroupPerm', 'conditions' = array( 'GroupPerm.group_id' = 'Group.id' ) ), array( 'type' = 'INNER', 'table' = 'perms', 'alias' = 'Perm', 'conditions' = array( 'GroupPerm.perm_id' = 'Perm.id' ) ) ) ) ); However, I've left out the perm.id='can_access_admin' part because it makes no sense in the context of Cake. The id column should be an INT. I presume you mean something like 'Perm.type' = 'can_access_admin', in which case add it to the 2nd joins conditions array. On Wed, Jan 2, 2013 at 3:48 PM, Stefano Campanella leon...@guildofmessengers.com javascript: wrote: mmh, ok. But the problem is that even if I change the find(count) into a find(all) it still loads data only from Group table. Yes I am using the AuthComponent for logged in users. But since I want to use my Authorize class also for managing what anonymous users can access I am calling $this-Auth-isAuthorized() in the beforeFilter of AppController with a $user parameter of array('id'=0). Inside the authorize method I recognize the empty user and make checks for permissions on an hard coded group id. I checked this would work correctly, if only I could make the query in the right way. Let's change the question. Which code would you write to make CakePHP execute this query: SELECT COUNT(*) AS count FROM groups INNER JOIN groups_perms ON groups.id=groups_perms.group_id INNER JOIN perm ON groups_perms.perm_id=perm.id WHERE group.id=1 AND perm.id='can_access_admin' given that you have access to $this-controller()-Group? Thanks On Wednesday, January 2, 2013 7:59:24 PM UTC+1, cricket wrote: When running a find('count') the contain param is useless. This is because the main query is fetching a sum, not a set of records from which to fetch the associated 'contain' records. Are you using AuthComponent? You can use that to fetch the User and associated records. However, I can't remember how deep it goes. To see what records it has, put this in your UsersController login method: die(debug($this-Auth-user()));
Re: queries on HABTM relationships
array('*id*'='can_access_admin') Do you have sure is ID? Usually ID is numeric. Em terça-feira, 1 de janeiro de 2013 19h23min58s UTC-3, Stefano Campanella escreveu: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
Yes I am sure. In my case id is not numeric, the permission name is already an identifier for the permission On Wednesday, January 2, 2013 3:56:41 PM UTC+1, Maicon Pinto wrote: array('*id*'='can_access_admin') Do you have sure is ID? Usually ID is numeric. Em terça-feira, 1 de janeiro de 2013 19h23min58s UTC-3, Stefano Campanella escreveu: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
queries on HABTM relationships
Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: queries on HABTM relationships
Have you looked at the inbuilt Auth and ACL components? Might save you a lot of time. Jeremy Burns Class Outfit http://www.classoutfit.com On 1 Jan 2013, at 22:23:58, Stefano Campanella leona...@guildofmessengers.com wrote: Hello all, this is my first time posting here. I recently started to study how to use CakePHP and I'm trying to develop a website. In my website I am writing a custom authorize component where each user get one or more groups and each group has one or more permissions associated to it. I have problems in using the find() method. This is my structure: User hasAndBelongsToMany Group Group hasAndBelongsToMany Perm I have attached Containable to all the Models (in AppModel) now in my authorization component I need to check if a group has a specific permission, and for this I use find(): if(!isset($this-controller()-Group)){ $this-controller()-loadModel('Group'); } $n_perm=$this-controller()-Group-find('count',array( 'conditions'=array('id'=1), 'contain'=array( 'Perm'=array( 'conditions' = array('id'='can_access_admin') ) ) )); I would expect this to give me a result =1 if group 1 has the 'can_access_admin' permission, and =0 if the group has no such permission. This is not what actually happens, the only query that cakePHP shows is this: SELECT COUNT(*) AS `count` FROM `groups` AS `Group` WHERE `id` = 1 And it is obviously not enough to find what I requested. Can anyone help me? Thanks -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
My Model Relationships don't work
I have three models: Category, Post, Attachment My Relations in these Models are: 1. Category hasMany Post hasMany Attachment 2. Post hasMany Attachment 3. Category hasMany Attachment My attachments table has the following fields: id, title, foreign_key, model The field model contains Category or Post. *The Error:* The CategoriesController don't show me the attachments of the posts (Category-Post-Attachment), but it show's me the attachments of the categories. Why? Is there something else to do? Thanks a lot for help, Regards Bettina -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: My Model Relationships don't work
On Tue, Nov 13, 2012 at 10:43 AM, Tsampika bettina.oberrau...@gmail.com wrote: I have three models: Category, Post, Attachment My Relations in these Models are: 1. Category hasMany Post hasMany Attachment 2. Post hasMany Attachment 3. Category hasMany Attachment My attachments table has the following fields: id, title, foreign_key, model The field model contains Category or Post. I've used this technique (foreign_key, model) often. Please post the $hasMany/$belongsTo settings for these models. The Error: The CategoriesController don't show me the attachments of the posts (Category-Post-Attachment), but it show's me the attachments of the categories. Why? Is there something else to do? Please also post the find() code. It may be just that it's not recursing deep enough. Or you are using 'contain' incorrectly. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
CakePHP hasAndBelongsToMany relationships demystified
Hi everybody, After days of trial-and-error and almost giving up, I've managed to get some basic and – as I believe – very common scenarios solved in CakePHP. I was wondering, why the documentation is not clear on these aspects, so I described my findings in a somewhat lengthy blog post. You might find this helpful: http://www.24100.net/2012/07/cakephp-hasandbelongstomany-relationship-queries-demystified/ . I'm addressing a couple of questions: - Scenario where a User and a Group model share a bidirectional hasAndBelongsToMany relationship. - Saving a user with *multiple groups*. - Querying for a user *who is a member of a specific group AND at the same time filtering on fields of the User model.* - Adding *additional groups* for an existing user *and keeping the join table up-to-date.* As I've read hundreds of questions somewhat related to this scenario on Stack Overflow, I assume there must be others out there, trying to wrap their heads around this. I hope it helps. Open for any conversation on Twitter, find me @ralfhttp://twitter.com/ralf . -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Conceptual questions regarding HABTM relationships!
I've been working with CakePHP (2.x) for quite a while and I'm loving it. However, I found some very important aspects covered too briefly in the documentation. When googling around and asking in other forums, I got mixed responses, increasing my feeling of uncertainty even more. I'd like to ask this group to help me (and possibly others) clarifying a few questions. I've used Pastie for code as I frequently find long code snippets in group posts hurting readability. Here we go: Assume I've got two models, User and Group related to each others in a HABTM relationship. Each user can have multiple groups and groups belong to multiple users. My simple model definition http://pastie.org/4307801 is here: http://pastie.org/4307801. Also, the join table *groups_users* exists with the appropriate columns following CakePHP's conventions. 1. Question: a) Assuming that all tables are empty, can I add a *new user* along with *a single new group* and the corresponding entries in the join table in one *single command*? I tried this http://pastie.org/4307843. The user gets created, but no group nor does anything get inserted into the join table. b) In case I did anything wrong in a) and it is in fact possible to create a User and Groups on the fly in one single command, is it also possible to create *multiple* groups? If so, would this http://pastie.org/4307863 be the correct way of doing it? c) Is this what *saveAll()* and *saveAssociated()* where meant for? 2. Question: What exactly is the difference between *save()*, *saveAll()* and * saveAssociated()*? 3. Question: In past versions of CakePHP it was difficult to have CakePHP add *additional * related items (= records to the join table) as CakePHP annoyingly deleted any existing records in the join table before adding new ones for an existing relationship. If, e.g. the user would join additional groups, there was no easy way doing it in CakePHP besides taking care for inserting the correct records in the join table yourself. As far as I remember somebody wrote a behavior to circumvent this but it didn't get updated and no longer works. What is the best way in CakePHP to add additional related objects (not new relationships!) when some already exist? Am I supposed to just manually * save()* records to the join table using the implicit join table model? 4. Question: Last but not least: Give the above and the use case, how would a professional, experience CakePHP developer handle the following use cases (code welcomed!): a) Adding the first group to an existing user. b) Later, adding additional groups to that user. c) Later, removing some of the groups. I hope to hear back from the community. You can also find me on Twitter @ralf http://twitter.com/ralf. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Two tables with multiple relationships
Hello Again Everyone- I'm having a bit of trouble establishing my databases. To sum up my application, it allows users to make modules which then can be viewed by other users of the creator's choice. So I have: User hasMany Module -- This is where I place the user id number of the creator of the module Module belongsTo User User HABTM Module -- This table is only for those who are allowed to view the module, but don't own it But I feel that this isn't the right way to do it. How should I implement this? Is it possible to do this solely in ACL? If so, how? Thanks to everyone in advance for their help! -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Two tables with multiple relationships
you can very well implement HABTM for users--modules relationship simplly including the owner as a user. Further in the controller or view,give condition for only owner to be able to edit. Or u can give a column as user_id in the module table, to track the owner of the modules, but if u go for HABTM, u can nytime change the privileges for the users in the future. On Wednesday, July 18, 2012 2:19:36 AM UTC+5:30, Andrew Johnston wrote: Hello Again Everyone- I'm having a bit of trouble establishing my databases. To sum up my application, it allows users to make modules which then can be viewed by other users of the creator's choice. So I have: User hasMany Module -- This is where I place the user id number of the creator of the module Module belongsTo User User HABTM Module -- This table is only for those who are allowed to view the module, but don't own it But I feel that this isn't the right way to do it. How should I implement this? Is it possible to do this solely in ACL? If so, how? Thanks to everyone in advance for their help! -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Saving relationships
I suggest you read this article: http://nuts-and-bolts-of-cakephp.com/2008/07/11/notes-on-cakephp-habtm-part-2-saving-data/ At the end you'll see a behavior where you can save one HABTM link at a time. Generally, you save all of the HABTM data because Cake wipes all of the current relationships and resaves them. That's the only way it knows not to get duplicates, or that you removed them. The HABTM behavior helps you save/delete single ones without needing to know the others, i.e., saving/removing one follower without knowledge of the other followers. Your follow button should go to something like /users/follow which in turn uses (probably POSTed so you don't have spamming) data and the HABTM behavior to save that new follower. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Saving relationships
your relations are in the controller - they should be in the model you don't need to loadModel follower as User hasMany followers - S On 22 January 2012 16:20, J. contact.mysparet...@gmail.com wrote: I'm making a follower system ala Twitter. Here is my UsersController : class UsersController extends AppController { public $name = 'Users'; public $helpers = array('Html', 'Form', 'Paginator'); var $hasAndBelongsToMany = array( 'Followed' = array( 'className' = 'User', 'joinTable' = 'followed', 'foreignKey' = 'user_id', 'associationForeignKey' = 'followed_id', ), 'Follower' = array( 'className' = 'User', 'joinTable' = 'followers', 'foreignKey' = 'user_id', 'associationForeignKey' = 'follower_id', ) ); My tables are : followers , containing user_id and follower_id followeds , containing user_id and followeds_id And finally I use this in my UsersController : public function view($id = null) { $this-loadModel('Follower'); $followers = $this-set('followers', $this-Follower-find('all', array('conditions' = array('Follower.user_id' = $id; $this-loadModel('Followed'); $followeds = $this-set('followeds', $this-Followed-find('all', array('conditions' = array('Followed.user_id' = $id; I use foreach to display it in the view. So when I set up numbers in the tables, everything works correctly, but I don't know how to make a follow button on user view. I'm discovering phh AND cake, and I have no idea how to do this. Thanks a lot for your time. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Saving relationships
I'm making a follower system ala Twitter. Here is my UsersController : class UsersController extends AppController { public $name = 'Users'; public $helpers = array('Html', 'Form', 'Paginator'); var $hasAndBelongsToMany = array( 'Followed' = array( 'className' = 'User', 'joinTable' = 'followed', 'foreignKey' = 'user_id', 'associationForeignKey' = 'followed_id', ), 'Follower' = array( 'className' = 'User', 'joinTable' = 'followers', 'foreignKey' = 'user_id', 'associationForeignKey' = 'follower_id', ) ); My tables are : followers , containing user_id and follower_id followeds , containing user_id and followeds_id And finally I use this in my UsersController : public function view($id = null) { $this-loadModel('Follower'); $followers = $this-set('followers', $this-Follower-find('all', array('conditions' = array('Follower.user_id' = $id; $this-loadModel('Followed'); $followeds = $this-set('followeds', $this-Followed-find('all', array('conditions' = array('Followed.user_id' = $id; I use foreach to display it in the view. So when I set up numbers in the tables, everything works correctly, but I don't know how to make a follow button on user view. I'm discovering phh AND cake, and I have no idea how to do this. Thanks a lot for your time. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Altering Relationships on the Fly
I just learned something and thought I would share. So I came across the need to apply a condition to a hasMany query. I was like how in the world do I do that? // Get all Checkpoints with Appropriate Spec $this-VehicleDailyLog-VehicleDailyLogCheckpoint-VehicleCheckpoint -hasMany['VehicleDailyLogCheckpoint']['conditions'][] = array( 'VehicleDailyLogCheckpoint.vehicle_id'=$vehicleIds, 'VehicleDailyLogCheckpoint.vehicle_daily_log_id'=$logIds ); You can access the conditions for the hasMany before you do the find! Awesome. Just as a little explanation... The VehicleDailyLogCheckpoint model holds a value that is tied to a daily log, a vehicle and the associated checkpoint. So, I get the vehicles, then I get the logs that are displayed, then I find the checkpoints. The checkpoints have many of these vehicle daily checkpoints, but I needed to limit them to only those that belong to the logs and vehicles... Just for fun! Happy Coding! -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Queries and Relationships(in DBs)
If I have a long list of ids(extracted from a table), and I have to pull out corresponding records from another table, can it be done via an iteration loop and stored in a *single* variable(so that it can be easily passed on to the view)? Or do I have to use Relationships? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Queries and Relationships(in DBs)
Add a condition to your find: 'conditions' = array('Model.field_name' = $yourArrayOfIds) Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 26 Apr 2011, at 17:03, goluhaque wrote: If I have a long list of ids(extracted from a table), and I have to pull out corresponding records from another table, can it be done via an iteration loop and stored in a single variable(so that it can be easily passed on to the view)? Or do I have to use Relationships? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Question about how models using different datasources handle relationships
Hi, I'm curious as to how models which use different datasources handle relationships? If i was to create a datasource to consume a web service, and I wanted it to pick up related fields via a HasOne relationship to a model using a mysql database table, will cake just automagically resolve this, or do I need to do something cute in the datasource? Sorry for no code examples or trying it first - its just a question that popped into my head and a quick browse of the book didn't seem to provide any insight. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Question about how models using different datasources handle relationships
On Tue, Feb 22, 2011 at 7:56 AM, Greg Skerman gsker...@gmail.com wrote: Hi, I'm curious as to how models which use different datasources handle relationships? If i was to create a datasource to consume a web service, and I wanted it to pick up related fields via a HasOne relationship to a model using a mysql database table, will cake just automagically resolve this, or do I need to do something cute in the datasource? Sorry for no code examples or trying it first - its just a question that popped into my head and a quick browse of the book didn't seem to provide any insight. I was also wondering this. Like you, it popped into my head last week while reading a discussion here about datasources. And I haven't got round to experimenting with it. My first thought was that it would be resolved somehow through the model cache. But how would the queries themselves be created? Perhaps we can't have associated models using different datasources. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: How to setup multiple HABTM relationships between two tables
You could consider adding a new column to your joining table that contains a tinyint. By default the value of that field is 0 (which indicates wants) but changes to 1 when he owns it. This assumes that someone can no longer 'want' something when they already 'own' it. Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 13 Jan 2011, at 07:14, Zaky Katalan-Ezra wrote: If you go with the status columns you need two boolean columns one for own and one for want, its a possible solution. If you want to use two table you can create users_want and users_own. The relation for each table should looks like it would be for items_users. The reason to prefer one implementation depend on your over all design and data distribution. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to setup multiple HABTM relationships between two tables
Thanks for replies... I added a two boolean columns to join table for owns and wants Thanks again!! On Jan 13, 3:13 am, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: You could consider adding a new column to your joining table that contains a tinyint. By default the value of that field is 0 (which indicates wants) but changes to 1 when he owns it. This assumes that someone can no longer 'want' something when they already 'own' it. Jeremy Burns Class Outfit jeremybu...@classoutfit.comhttp://www.classoutfit.com On 13 Jan 2011, at 07:14, Zaky Katalan-Ezra wrote: If you go with the status columns you need two boolean columns one for own and one for want, its a possible solution. If you want to use two table you can create users_want and users_own. The relation for each table should looks like it would be for items_users. The reason to prefer one implementation depend on your over all design and data distribution. Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to setup multiple HABTM relationships between two tables
On Thu, Jan 13, 2011 at 3:55 PM, mklappen mklap...@gmail.com wrote: Thanks for replies... I added a two boolean columns to join table for owns and wants You might be interested in modelizing the join table like this: http://book.cakephp.org/view/1650/hasMany-through-The-Join-Model Also, as Jeremy suggested, consider using a single column if a User cannot both own and want an Item. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
How to setup multiple HABTM relationships between two tables
Hi All I'm having a little difficulty conceptualizing the relationships when setting up a database/models, for a app I'm starting to develop. If I'm creating a basic inventory management application I have the following: Table Name | Columns users | id, user_name, email, etc... items | id, name, description, etc... items_users | id, item_id, user_id I want a user to be able to mark items as owns or wants and a user can own many items and items can be owned my many users. Similarly wants would have same HABTM relationship between users and items. Now I can set up the HABTM relationship table items_users but that will only get me one relationship between users and items. (either the owns or wants). In order to get the second relationship type do I need to set up a second relationship table? if so what would the naming conventions be? Or do I add a another column to items_users table called itemstatus and have values such as owns, wants, owns wants... More or less looking for the best approach and/or other suggestions. Thanks in advance. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to setup multiple HABTM relationships between two tables
It all depends! What is the requirement for owning items? Can a user own more than one of the same item? What is the requirement for wanting items? Can a user want more than one of the same item? Can a want record expire - ie. the user wants the item, but only if the user can get it within X days/months/years? I would probably go for the two intersection tables between users and items, with the first storing all the owned items, one record each, and the second storing all the wanted items. When then the user gets the wanted item, I would remove it from the second and insert it into the first. Well, you can think about it. Enjoy, John On 12 Jan., 21:13, mklappen mklap...@gmail.com wrote: Hi All I'm having a little difficulty conceptualizing the relationships when setting up a database/models, for a app I'm starting to develop. If I'm creating a basic inventory management application I have the following: Table Name | Columns users | id, user_name, email, etc... items | id, name, description, etc... items_users | id, item_id, user_id I want a user to be able to mark items as owns or wants and a user can own many items and items can be owned my many users. Similarly wants would have same HABTM relationship between users and items. Now I can set up the HABTM relationship table items_users but that will only get me one relationship between users and items. (either the owns or wants). In order to get the second relationship type do I need to set up a second relationship table? if so what would the naming conventions be? Or do I add a another column to items_users table called itemstatus and have values such as owns, wants, owns wants... More or less looking for the best approach and/or other suggestions. Thanks in advance. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to setup multiple HABTM relationships between two tables
If you go with the status columns you need two boolean columns one for own and one for want, its a possible solution. If you want to use two table you can create users_want and users_own. The relation for each table should looks like it would be for items_users. The reason to prefer one implementation depend on your over all design and data distribution. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Using USE INDEX or FORCE INDEX in Model-find relationships
kadanis wrote: Just wondering if anyone has any suggestions on this. I'm using Cake for a current project and the project lead is insisting we use FORCE INDEX on the queries and table joins. Recently I've play with it a little. My workaround is: 1. Create my own datasource - (in my case extending DboMysql) data source has two tasks: its overrides read method and checks if model has set useIndex field if (!empty($model-useIndex)) { $this-useIndex = $model-useIndex; } return parent::read($model, $queryData); and it overrides renderStatement method and if $model-useIndex field was set, adding its value after table alias in select statement. if (strtolower($type) == 'select' !empty($this-useIndex)) { $res = SELECT {$fields} FROM {$table} {$alias} {$this-useIndex} {$joins} {$conditions} {$group} {$order} {$limit}; } else { $res = parent::renderStatement($type, $data); } $this-useIndex = null; return $res; 2. Setting up model field whitch contains sql part of use index, force index or ignore index eg in controller: $this-Task-useIndex = 'IGNORE INDEX(ind_usr_id)'; $this-paginate = array( 'fields' = array('Task.id', 'Task.name','User.id', 'User.name'), 'order' = 'Task.id', 'limit' = 10 ); $this-paginate('Task'); To make it work, you should also set this datasource as datasource for your model. In fact, this is rather experimental and I didn't use it in production environment yet :), but mayby it can help you. -- Przemoo -- View this message in context: http://cakephp.1045679.n5.nabble.com/Using-USE-INDEX-or-FORCE-INDEX-in-Model-find-relationships-tp3281552p3300205.html Sent from the CakePHP mailing list archive at Nabble.com. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Using USE INDEX or FORCE INDEX in Model-find relationships
Thanks for the reply. That's give me something to think about. I've not used finderQuery before, I'll certainly give it some time. Thanks again. On Nov 27, 12:20 am, cricket zijn.digi...@gmail.com wrote: On Fri, Nov 26, 2010 at 12:03 PM, kadanis evad.ba...@gmail.com wrote: Just wondering if anyone has any suggestions on this. I'm using Cake for a current project and the project lead is insisting we use FORCE INDEX on the queries and table joins. I've searched all over the web and come up empty handed so far and don't particularly want to hand code all the sql queries in Model- query(). I have looked at the core and managed to hack it to get the desired results, but its a nasty hack and not sustainable through upgrades of the Cake core code. Anyone have any suggestions, they would be greatly appreciated! I suspect that you could use a finderQuery for this. Unfortunately, it's poorly documented (no surprise). Search for cakephp finderquery. And ask your project lead if he/she has seen this:http://www.mysqldiary.com/the-battle-between-force-index-and-the-quer... Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Using USE INDEX or FORCE INDEX in Model-find relationships
Just wondering if anyone has any suggestions on this. I'm using Cake for a current project and the project lead is insisting we use FORCE INDEX on the queries and table joins. I've searched all over the web and come up empty handed so far and don't particularly want to hand code all the sql queries in Model- query(). I have looked at the core and managed to hack it to get the desired results, but its a nasty hack and not sustainable through upgrades of the Cake core code. Anyone have any suggestions, they would be greatly appreciated! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Using USE INDEX or FORCE INDEX in Model-find relationships
On Fri, Nov 26, 2010 at 12:03 PM, kadanis evad.ba...@gmail.com wrote: Just wondering if anyone has any suggestions on this. I'm using Cake for a current project and the project lead is insisting we use FORCE INDEX on the queries and table joins. I've searched all over the web and come up empty handed so far and don't particularly want to hand code all the sql queries in Model- query(). I have looked at the core and managed to hack it to get the desired results, but its a nasty hack and not sustainable through upgrades of the Cake core code. Anyone have any suggestions, they would be greatly appreciated! I suspect that you could use a finderQuery for this. Unfortunately, it's poorly documented (no surprise). Search for cakephp finderquery. And ask your project lead if he/she has seen this: http://www.mysqldiary.com/the-battle-between-force-index-and-the-query-optimizer/ Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
What are the links between relationships and containable?
Basically, can containable work without having relationships specified? Or does containable rely on those relationships? In some tutorials, they specify to use recursive = -1 and then containable to get more optimized SQL. I can't help but think, what's the point specifying the relationships?? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
Do you mean relationships in the database or in the models? They are essential in the models (else Cake won't know how to relate models) and although not a Cake requirement I'd say it is paramount from a performance point of view in the database. Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 18 Nov 2010, at 12:29, Dan wrote: Basically, can containable work without having relationships specified? Or does containable rely on those relationships? In some tutorials, they specify to use recursive = -1 and then containable to get more optimized SQL. I can't help but think, what's the point specifying the relationships?? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
I meant Model relationships. So, they would be required for the containable behavior to work then? On Nov 18, 8:38 am, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: Do you mean relationships in the database or in the models? They are essential in the models (else Cake won't know how to relate models) and although not a Cake requirement I'd say it is paramount from a performance point of view in the database. Jeremy Burns Class Outfit jeremybu...@classoutfit.comhttp://www.classoutfit.com On 18 Nov 2010, at 12:29, Dan wrote: Basically, can containable work without having relationships specified? Or does containable rely on those relationships? In some tutorials, they specify to use recursive = -1 and then containable to get more optimized SQL. I can't help but think, what's the point specifying the relationships?? Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
Yes. If you try and contain a model that is not related (with $hasMany, $belongsTo etc) it will error. Don't forget that you can daisy chain them too by using nested arrays. So if you have: User-Profile-ProfileData-ProfileDataType ...you can do: $result = $this-User-find( 'all', array( 'contain' = array( 'Profile' = array( 'ProfileData' = array( 'ProfileDataType' ) ) ) ) ); Happy to be corrected, but I think recursion is redundant when using contain, so no need to set it to -1 (although I suppose it doesn't hurt). Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 18 Nov 2010, at 13:32, Dan wrote: I meant Model relationships. So, they would be required for the containable behavior to work then? On Nov 18, 8:38 am, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: Do you mean relationships in the database or in the models? They are essential in the models (else Cake won't know how to relate models) and although not a Cake requirement I'd say it is paramount from a performance point of view in the database. Jeremy Burns Class Outfit jeremybu...@classoutfit.comhttp://www.classoutfit.com On 18 Nov 2010, at 12:29, Dan wrote: Basically, can containable work without having relationships specified? Or does containable rely on those relationships? In some tutorials, they specify to use recursive = -1 and then containable to get more optimized SQL. I can't help but think, what's the point specifying the relationships?? Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
@jeremy yes, redundant as long as you dont use find(list) in this case (i consider it a bug which i already reported) you will need containable On 18 Nov., 14:54, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: Yes. If you try and contain a model that is not related (with $hasMany, $belongsTo etc) it will error. Don't forget that you can daisy chain them too by using nested arrays. So if you have: User-Profile-ProfileData-ProfileDataType ...you can do: $result = $this-User-find( 'all', array( 'contain' = array( 'Profile' = array( 'ProfileData' = array( 'ProfileDataType' ) ) ) ) ); Happy to be corrected, but I think recursion is redundant when using contain, so no need to set it to -1 (although I suppose it doesn't hurt). Jeremy Burns Class Outfit jeremybu...@classoutfit.comhttp://www.classoutfit.com On 18 Nov 2010, at 13:32, Dan wrote: I meant Model relationships. So, they would be required for the containable behavior to work then? On Nov 18, 8:38 am, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: Do you mean relationships in the database or in the models? They are essential in the models (else Cake won't know how to relate models) and although not a Cake requirement I'd say it is paramount from a performance point of view in the database. Jeremy Burns Class Outfit jeremybu...@classoutfit.comhttp://www.classoutfit.com On 18 Nov 2010, at 12:29, Dan wrote: Basically, can containable work without having relationships specified? Or does containable rely on those relationships? In some tutorials, they specify to use recursive = -1 and then containable to get more optimized SQL. I can't help but think, what's the point specifying the relationships?? Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
When using contain, I have to specify the $actAs = Containable for it to work, correct? And if you have a linking table (HABTM), would you have to specify that model in the contain statement or can it be omitted (figured out by Cake)? On Nov 18, 10:03 am, euromark dereurom...@googlemail.com wrote: @jeremy yes, redundant as long as you dont use find(list) in this case (i consider it a bug which i already reported) you will need containable On 18 Nov., 14:54, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: Yes. If you try and contain a model that is not related (with $hasMany, $belongsTo etc) it will error. Don't forget that you can daisy chain them too by using nested arrays. So if you have: User-Profile-ProfileData-ProfileDataType ...you can do: $result = $this-User-find( 'all', array( 'contain' = array( 'Profile' = array( 'ProfileData' = array( 'ProfileDataType' ) ) ) ) ); Happy to be corrected, but I think recursion is redundant when using contain, so no need to set it to -1 (although I suppose it doesn't hurt). Jeremy Burns Class Outfit jeremybu...@classoutfit.comhttp://www.classoutfit.com On 18 Nov 2010, at 13:32, Dan wrote: I meant Model relationships. So, they would be required for the containable behavior to work then? On Nov 18, 8:38 am, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: Do you mean relationships in the database or in the models? They are essential in the models (else Cake won't know how to relate models) and although not a Cake requirement I'd say it is paramount from a performance point of view in the database. Jeremy Burns Class Outfit jeremybu...@classoutfit.comhttp://www.classoutfit.com On 18 Nov 2010, at 12:29, Dan wrote: Basically, can containable work without having relationships specified? Or does containable rely on those relationships? In some tutorials, they specify to use recursive = -1 and then containable to get more optimized SQL. I can't help but think, what's the point specifying the relationships?? Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
On Thu, Nov 18, 2010 at 11:03 AM, Dan dannyetdi...@gmail.com wrote: When using contain, I have to specify the $actAs = Containable for it to work, correct? Yes, of course. Just as with any other behavior. If you plan to use it a lot you can put it in AppModel's $actsAs array. And if you have a linking table (HABTM), would you have to specify that model in the contain statement or can it be omitted (figured out by Cake)? You have to specify all models for which you want data, and there must be a chain of association running through them. If you have User - Comment, and Comment - Tag, and you want a User's Tags, you must specify Comment in your contain array so that the behavior can work out how to get at Tag (and which ones to look for). Although it's not necessary to fetch the entire Comment, if you do provide a fields array for any of the contained models it should include the primary key and any relevant foreign keys. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
And don't forget it's $actsAs, not $actAs (cricket has identified this in his response). Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 18 Nov 2010, at 17:45, cricket wrote: On Thu, Nov 18, 2010 at 11:03 AM, Dan dannyetdi...@gmail.com wrote: When using contain, I have to specify the $actAs = Containable for it to work, correct? Yes, of course. Just as with any other behavior. If you plan to use it a lot you can put it in AppModel's $actsAs array. And if you have a linking table (HABTM), would you have to specify that model in the contain statement or can it be omitted (figured out by Cake)? You have to specify all models for which you want data, and there must be a chain of association running through them. If you have User - Comment, and Comment - Tag, and you want a User's Tags, you must specify Comment in your contain array so that the behavior can work out how to get at Tag (and which ones to look for). Although it's not necessary to fetch the entire Comment, if you do provide a fields array for any of the contained models it should include the primary key and any relevant foreign keys. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: What are the links between relationships and containable?
On Thu, Nov 18, 2010 at 1:02 PM, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: And don't forget it's $actsAs, not $actAs (cricket has identified this in his response). I hadn't noticed. Been bit by that a couple of times (as with not providing the keys in 'fields'). Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about DB relationships
Oh my word - you just made that so easy! Thank you so much for your detailed explanation - it is obvious you put some time into this question for me. Thanks again - I owe you! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about DB relationships
How would one change the label that is generated in this example? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about DB relationships
On Thu, Oct 28, 2010 at 7:38 PM, dingerkingh dingerki...@hotmail.com wrote: How would one change the label that is generated in this example? label? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Question about DB relationships
I will try to keep this as simple as possible. I have read through the manual but can't seem to find what I am looking - however, I am sure it is in there somewhere. Here is what I am I am looking to do on a very small scale: names id name tickets id title name_id closed_by What I need to have is closed_by be the same thing as name_id. When I use name_id and cake bake it automagically creates the drop downs for the add and edit page because it is linked to the names table. How would I make closed_by do the same thing? I hope this makes sense... name_id and closed_id I would like both to be generated from the names table. Thanks in advance! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about DB relationships
On Wed, Oct 27, 2010 at 7:18 PM, dingerkingh dingerki...@hotmail.com wrote: I will try to keep this as simple as possible. I have read through the manual but can't seem to find what I am looking - however, I am sure it is in there somewhere. Here is what I am I am looking to do on a very small scale: names id name tickets id title name_id closed_by What I need to have is closed_by be the same thing as name_id. When I use name_id and cake bake it automagically creates the drop downs for the add and edit page because it is linked to the names table. How would I make closed_by do the same thing? I hope this makes sense... name_id and closed_id I would like both to be generated from the names table. Thanks in advance! What you're after is a self-join relationship. To do that, you use a model alias but the same classname. That's why, in the association arrays, you'll see something like: 'SomeModelName' = array( 'className' = 'SomeModelName', etc. The reason for the repetition is that the outer array key is the model's alias. Often, the alias and class name are one and the same, so it seems pointless at first, but it's very, /very/ cool. So, to do a self-join on Foo model, where each Foo might have a parent and children: public $belongsTo = array( 'ParentFoo' = array( 'className' = 'Foo', 'foreignKey' = 'parent_id' ), ); public $hasMany = array( 'ChildFoo' = array( 'className' = 'Foo', 'foreignKey' = 'parent_id' ), ); So, for ParentFoo, we're checking Foo.parent_id, while the association between the latter is Foo.id == ChildFoo.parent_id. For your situation, I recommend that you use a different model name. Names are attributes, not things, which is why you've also got a column called 'name'. Name.name just seems a bit off, and suggests that the model/class hasn't really been thought through. Better: User, Member, Person, Flunky ... So: class Member extends AppModel { public $hasMany = array( 'Ticket' = array( 'className' = 'Ticket', 'foreignKey' = 'member_id' ) ); class Ticket extends AppModel { public $belongsTo = array( 'Opener' = array( 'className' = 'Member' 'foreignKey' = 'opener_id' ), 'Closer' = array( 'className' = 'Member', 'foreignKey' = 'closer_id' ) ); Now, in your TicketsController, you can do stuff like: public $paginate = array( 'limit' = 30, 'order' = array('Ticket.created' = ASC'), 'contain' = array( 'Opener', 'Closer' ) ); You'll then have 'Opener' and 'Closer' (if the Ticket has been closed) sub-arrays in your paginated data which contain Member info. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Dynamic menu based on deep relationships
Ah thanks for your help, I managed to sort it out. Got it working quite nicely with ajax menu on the sidenav. /countries/view/204 is the main screen showing the provinces for the country (only one country now, so countries arent really used) /provinces/view/xxx views the regions belonging to the province the ajax menu calls /(currentaction)/ajaxmenu/(currentvalue) so even if a user goes directly to a region/suburb etc then the ajax menu will start where it should. Thanks for your help though, managed to get it sorted after a stroke of genius! On Aug 30, 6:53 am, Sam s...@masterscommission360.com wrote: I think I know what you want but I'm not sure... let me know if I'm close. I'd do it one of two ways 1) User selects a province, page refreshes and now there are two dropdown boxes, first one has province selected, in the second user chooses region(and so forth) 2) User selects a province, select box appears with regions in that province(and so on and so forth) For method 1 I'd have the javascript submit the page each time a dropdown is changed- then the controller can figure out which menu items to load for the next select box. If several select boxes have been chosen, such as province, region and suburb, and province is changed, then the form would basically reset to only show the province and region select boxes. For method 2 I'd either use ajax to query the database based on the change in any of the select boxes, and reload the values in the select boxes. When the last select is chosen it loads the proper view. As for the menu knowing where the user is, simply set the relevant fields(province_id, region_id, suburb_id and establishment_id) based on the data that is loaded... if you load a suburb it should be relatively easy to get the region_id and province_id for that suburb. On Aug 29, 10:59 am, Bryan Paddock bryanpadd...@gmail.com wrote: Hey all, I've looked through pretty much every menu tutorial out there for cakephp and have sat for ages to try and think up how I can achieve this but to no avail. I have a semi-complex database structure of establishments (restaurants, hotels etc). Province - Region - Suburb - Establishment as well as Category - Subcategory - Establishment Now the user needs to be able to select the province from the list, have it show the regions under that province, then the suburbs, then a list of subcategories under that province that contain establishments. I can handle the fetching the data (eg how to pull out the list using containable etc) but it's the starting foundation I'm having problems figuring out. IT will be done in ajax but the actual ajax part I could probably do myself. I would like to have the menu also build itself from the page that the user is on (eg the user can browse around the menu in itself but if he also goes to the a related page (eg suburbs/view/cape-town) then the menu should know where the user is) I honestly can't think of even where I should start here. Building a menu is simple in plain php with simple relationships but it's getting pretty tricky with all the extra levels. Does anyone have any advice on a starting point which I could work with... I'm trying to make it extendable in the sense that I don't want to hard code anything. I'm starting to think it may be better off to handle the menu separately in a menu model and update the menu on each of the related models afterSave(), etc callback but that seems a bit unnecessary as it would just be duplicated data. Thanks in advance! Bryan Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Dynamic menu based on deep relationships
Hey all, I've looked through pretty much every menu tutorial out there for cakephp and have sat for ages to try and think up how I can achieve this but to no avail. I have a semi-complex database structure of establishments (restaurants, hotels etc). Province - Region - Suburb - Establishment as well as Category - Subcategory - Establishment Now the user needs to be able to select the province from the list, have it show the regions under that province, then the suburbs, then a list of subcategories under that province that contain establishments. I can handle the fetching the data (eg how to pull out the list using containable etc) but it's the starting foundation I'm having problems figuring out. IT will be done in ajax but the actual ajax part I could probably do myself. I would like to have the menu also build itself from the page that the user is on (eg the user can browse around the menu in itself but if he also goes to the a related page (eg suburbs/view/cape-town) then the menu should know where the user is) I honestly can't think of even where I should start here. Building a menu is simple in plain php with simple relationships but it's getting pretty tricky with all the extra levels. Does anyone have any advice on a starting point which I could work with... I'm trying to make it extendable in the sense that I don't want to hard code anything. I'm starting to think it may be better off to handle the menu separately in a menu model and update the menu on each of the related models afterSave(), etc callback but that seems a bit unnecessary as it would just be duplicated data. Thanks in advance! Bryan Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Dynamic menu based on deep relationships
I think I know what you want but I'm not sure... let me know if I'm close. I'd do it one of two ways 1) User selects a province, page refreshes and now there are two dropdown boxes, first one has province selected, in the second user chooses region(and so forth) 2) User selects a province, select box appears with regions in that province(and so on and so forth) For method 1 I'd have the javascript submit the page each time a dropdown is changed- then the controller can figure out which menu items to load for the next select box. If several select boxes have been chosen, such as province, region and suburb, and province is changed, then the form would basically reset to only show the province and region select boxes. For method 2 I'd either use ajax to query the database based on the change in any of the select boxes, and reload the values in the select boxes. When the last select is chosen it loads the proper view. As for the menu knowing where the user is, simply set the relevant fields(province_id, region_id, suburb_id and establishment_id) based on the data that is loaded... if you load a suburb it should be relatively easy to get the region_id and province_id for that suburb. On Aug 29, 10:59 am, Bryan Paddock bryanpadd...@gmail.com wrote: Hey all, I've looked through pretty much every menu tutorial out there for cakephp and have sat for ages to try and think up how I can achieve this but to no avail. I have a semi-complex database structure of establishments (restaurants, hotels etc). Province - Region - Suburb - Establishment as well as Category - Subcategory - Establishment Now the user needs to be able to select the province from the list, have it show the regions under that province, then the suburbs, then a list of subcategories under that province that contain establishments. I can handle the fetching the data (eg how to pull out the list using containable etc) but it's the starting foundation I'm having problems figuring out. IT will be done in ajax but the actual ajax part I could probably do myself. I would like to have the menu also build itself from the page that the user is on (eg the user can browse around the menu in itself but if he also goes to the a related page (eg suburbs/view/cape-town) then the menu should know where the user is) I honestly can't think of even where I should start here. Building a menu is simple in plain php with simple relationships but it's getting pretty tricky with all the extra levels. Does anyone have any advice on a starting point which I could work with... I'm trying to make it extendable in the sense that I don't want to hard code anything. I'm starting to think it may be better off to handle the menu separately in a menu model and update the menu on each of the related models afterSave(), etc callback but that seems a bit unnecessary as it would just be duplicated data. Thanks in advance! Bryan Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Relationships
Hi all. Sorry for all these newb questions... trying to learn this stuff. Here's the relationships and tables I have: Relationships: Hardware HABTM Configuration Configuration belongsTo ConfigurationType Tables: configurations - configuration_type_id configurations_hardwares - configuration_id - hardware_id configuration_types hardwares When pulling the information for a specific Hardware record, I'm successfully getting the Configurations associated with it, but I'm not getting the information from the configuration_types table. How do I get info from this other table? ?php $options['conditions'] = array('Hardware.id'=$id); $this-Hardware-find('first', $options); ? produces... Array ( [Hardware] = Array ( [id] = 3 [hardware_type_id] = 2 [name] = w-irv-win7dev [description] = Philip Thompson's Windows 7 machine [location_id] = 1 ) [Configuration] = Array ( [0] = Array ( [id] = 1 [configuration_type_id] = 1 [configuration] = Windows 7 Professional [description] = [ConfigurationsHardware] = Array ( [id] = 1 [configuration_id] = 1 [hardware_id] = 3 ) ) [1] = Array ( [id] = 3 [configuration_type_id] = 5 [configuration] = Yes [description] = [ConfigurationsHardware] = Array ( [id] = 2 [configuration_id] = 3 [hardware_id] = 3 ) ) ) ) I get the configuration_type_id result, but I want other fields from configuration_type. Any help would be greatly appreciated on how to accomplish this! Thanks in advance, ~Philip http://lonestarlightandsound.com/ Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Relationships
On Tue, Aug 24, 2010 at 2:31 PM, Philip Thompson philthath...@gmail.com wrote: Hi all. Sorry for all these newb questions... trying to learn this stuff. Here's the relationships and tables I have: Relationships: Hardware HABTM Configuration Configuration belongsTo ConfigurationType Tables: configurations - configuration_type_id configurations_hardwares - configuration_id - hardware_id configuration_types hardwares When pulling the information for a specific Hardware record, I'm successfully getting the Configurations associated with it, but I'm not getting the information from the configuration_types table. How do I get info from this other table? ?php $options['conditions'] = array('Hardware.id'=$id); $this-Hardware-find('first', $options); ? produces... Array ( [Hardware] = Array ( [id] = 3 [hardware_type_id] = 2 [name] = w-irv-win7dev [description] = Philip Thompson's Windows 7 machine [location_id] = 1 ) [Configuration] = Array ( [0] = Array ( [id] = 1 [configuration_type_id] = 1 [configuration] = Windows 7 Professional [description] = [ConfigurationsHardware] = Array ( [id] = 1 [configuration_id] = 1 [hardware_id] = 3 ) ) [1] = Array ( [id] = 3 [configuration_type_id] = 5 [configuration] = Yes [description] = [ConfigurationsHardware] = Array ( [id] = 2 [configuration_id] = 3 [hardware_id] = 3 ) ) ) ) I get the configuration_type_id result, but I want other fields from configuration_type. Any help would be greatly appreciated on how to accomplish this! You need to increase the recursive value: $options['recursive'] = 2; I recommend you take a look at ContainableBehavior, though. It gives one much more control (recursive == 2 can fetch too much data). Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Relationships
On Aug 24, 2010, at 6:03 PM, cricket wrote: On Tue, Aug 24, 2010 at 2:31 PM, Philip Thompson philthath...@gmail.com wrote: Hi all. Sorry for all these newb questions... trying to learn this stuff. Here's the relationships and tables I have: Relationships: Hardware HABTM Configuration Configuration belongsTo ConfigurationType Tables: configurations - configuration_type_id configurations_hardwares - configuration_id - hardware_id configuration_types hardwares When pulling the information for a specific Hardware record, I'm successfully getting the Configurations associated with it, but I'm not getting the information from the configuration_types table. How do I get info from this other table? ?php $options['conditions'] = array('Hardware.id'=$id); $this-Hardware-find('first', $options); ? produces... Array ( [Hardware] = Array ( [id] = 3 [hardware_type_id] = 2 [name] = w-irv-win7dev [description] = Philip Thompson's Windows 7 machine [location_id] = 1 ) [Configuration] = Array ( [0] = Array ( [id] = 1 [configuration_type_id] = 1 [configuration] = Windows 7 Professional [description] = [ConfigurationsHardware] = Array ( [id] = 1 [configuration_id] = 1 [hardware_id] = 3 ) ) [1] = Array ( [id] = 3 [configuration_type_id] = 5 [configuration] = Yes [description] = [ConfigurationsHardware] = Array ( [id] = 2 [configuration_id] = 3 [hardware_id] = 3 ) ) ) ) I get the configuration_type_id result, but I want other fields from configuration_type. Any help would be greatly appreciated on how to accomplish this! You need to increase the recursive value: $options['recursive'] = 2; I recommend you take a look at ContainableBehavior, though. It gives one much more control (recursive == 2 can fetch too much data). Excellent! Thanks for your help. It worked! ~Philip http://lonestarlightandsound.com/ Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Using test cases with model relationships throws error
Hi, thanks for getting back to me. I definitely have all my models listed in the fixtures collection. What we just discovered after a lot of testing is that it had to do with $useTable being set to false. For some reason that just throws everything out of whack. If anybody gets this in the future, remember that when using fixtures/designing models that you don't need to put $useTable=false in, as you're technically using test tables! Cheers. On Aug 5, 5:41 pm, jharris funeralm...@gmail.com wrote: My best guess, without seeing your test case or fixtures, is that you need to add the fixture to your $fixtures var in your test case. i.e., class MenuItemTestCase extends CakeTestCase { var $fixtures = array('app.menu_item', 'app.alias'); } After doing that, they should load into the test DB. Whether or not you choose to load them manually or automatically (default) is up to you. I'm fairly new to unit testing but it's been my experience so far that if a fixture model is related in any way to another model, you'll need to include that in your $fixtures var as well. In my case, I have to include every model into the $fixtures var. hth, jeremy On Aug 4, 7:43 am, generaltao general...@gmail.com wrote: Hi all, Having a strange problem with test cases here. We have two tables in question in this one example - Alias and MenuItem. - Alias belongsTo MenuItem - MenuItem hasMany Alias I am running model test cases on Alias itself. Problem is that if I define the MenuItem hasMany Alias relationship in the MenuItem itself I get a full-stop error saying Database table aliases for model Alias was not found. This is quite obviously bizarre, especially because the prob seems to come from MenuItem model itself. Specific points that are bizarre about this 1) For some reason it seems to outright forget to use test_suite_aliases instead of Alias (I have no tables defined for Alias, hence using fixtures!) 2) I never say in my fixtures to import the model! I was under the impression you needed to do var $import in the fixture to tell it to import model, records, etc. but I'm not doing so in either fixture here. The only thing I have in my fixtures is the standard $name, $records, and $fields. Can anyone shed some light on this situation? Why is it forgetting to use test_suite_alias if the hasMany is defined in the model? Why is it using model stuff to begin with? Cheers! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Using test cases with model relationships throws error
My best guess, without seeing your test case or fixtures, is that you need to add the fixture to your $fixtures var in your test case. i.e., class MenuItemTestCase extends CakeTestCase { var $fixtures = array('app.menu_item', 'app.alias'); } After doing that, they should load into the test DB. Whether or not you choose to load them manually or automatically (default) is up to you. I'm fairly new to unit testing but it's been my experience so far that if a fixture model is related in any way to another model, you'll need to include that in your $fixtures var as well. In my case, I have to include every model into the $fixtures var. hth, jeremy On Aug 4, 7:43 am, generaltao general...@gmail.com wrote: Hi all, Having a strange problem with test cases here. We have two tables in question in this one example - Alias and MenuItem. - Alias belongsTo MenuItem - MenuItem hasMany Alias I am running model test cases on Alias itself. Problem is that if I define the MenuItem hasMany Alias relationship in the MenuItem itself I get a full-stop error saying Database table aliases for model Alias was not found. This is quite obviously bizarre, especially because the prob seems to come from MenuItem model itself. Specific points that are bizarre about this 1) For some reason it seems to outright forget to use test_suite_aliases instead of Alias (I have no tables defined for Alias, hence using fixtures!) 2) I never say in my fixtures to import the model! I was under the impression you needed to do var $import in the fixture to tell it to import model, records, etc. but I'm not doing so in either fixture here. The only thing I have in my fixtures is the standard $name, $records, and $fields. Can anyone shed some light on this situation? Why is it forgetting to use test_suite_alias if the hasMany is defined in the model? Why is it using model stuff to begin with? Cheers! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Using test cases with model relationships throws error
Hi all, Having a strange problem with test cases here. We have two tables in question in this one example - Alias and MenuItem. - Alias belongsTo MenuItem - MenuItem hasMany Alias I am running model test cases on Alias itself. Problem is that if I define the MenuItem hasMany Alias relationship in the MenuItem itself I get a full-stop error saying Database table aliases for model Alias was not found. This is quite obviously bizarre, especially because the prob seems to come from MenuItem model itself. Specific points that are bizarre about this 1) For some reason it seems to outright forget to use test_suite_aliases instead of Alias (I have no tables defined for Alias, hence using fixtures!) 2) I never say in my fixtures to import the model! I was under the impression you needed to do var $import in the fixture to tell it to import model, records, etc. but I'm not doing so in either fixture here. The only thing I have in my fixtures is the standard $name, $records, and $fields. Can anyone shed some light on this situation? Why is it forgetting to use test_suite_alias if the hasMany is defined in the model? Why is it using model stuff to begin with? Cheers! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Relationships with a common table
http://book.cakephp.org/view/1046/Multiple-relations-to-the-same-model Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 27 Jun 2010, at 13:13, jtomka wrote: Hey guys, I'm new to CakePHP and already stuck. I'm trying to use a common contact table and multiple tables, each referencing it one or more times. The schema goes something like this: contacts (id, name, address, phone, email) practice_sites (id, title, contact_id) practitioners (id, contact_id, qualifications) clients (id, contact_id, emergency_id, guardian_id) // each referencing the contact table Now how do I define relationships between the common contact table and each of the remaining ones? I'd love to be able to say practice_site hasone contact, practitioner hasone contact, client hasone contact. Related to my schema design, is there a (generic, reusable) way to make the contact record creation/update a part of creation/update of a record referencing it? E.g. client add/edit form containing the contact table fields (as opposed to scaffolding's reference dropdown)? Cheers, Jan Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Relationships with a common table
Hey guys, I'm new to CakePHP and already stuck. I'm trying to use a common contact table and multiple tables, each referencing it one or more times. The schema goes something like this: contacts (id, name, address, phone, email) practice_sites (id, title, contact_id) practitioners (id, contact_id, qualifications) clients (id, contact_id, emergency_id, guardian_id) // each referencing the contact table Now how do I define relationships between the common contact table and each of the remaining ones? I'd love to be able to say practice_site hasone contact, practitioner hasone contact, client hasone contact. Related to my schema design, is there a (generic, reusable) way to make the contact record creation/update a part of creation/update of a record referencing it? E.g. client add/edit form containing the contact table fields (as opposed to scaffolding's reference dropdown)? Cheers, Jan Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Problem with database cascade relationships.
You can't specify a condition on a hasMany association as Cake cannot create a join on such an association. In order to get a one to many result set you need to run 2 queries, 1 to find the product and another to find it's many types as such you are getting a logical error thrown back at you. You need to look at forcing joins using http://book.cakephp.org/view/86/Creating-and-Destroying-Associations-on-the-Fly or http://book.cakephp.org/view/872/Joining-tables HTH Paul Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Problem with database cascade relationships.
Nobody knows how to solve this problem? I think that it is very essential. Any help will be appreciated. I can't continue my work without it :/ Kine regards, T. On 28 Maj, 01:01, 朝の木 asan...@gmail.com wrote: Here is full statement *generated by cake*. It raises sql-error: SELECT `TestProduct`.`title`, `TestType`.`description`, `TestProductItem`.`size`, COUNT(*) FROM `test_product_items` AS `TestProductItem` LEFT JOIN `test_products` AS `TestProduct` ON (`TestProductItem`.`test_product_id` = `TestProduct`.`id`) WHERE 1 = 1 GROUP BY `TestProduct`.`id`, `TestProductItem`.`size` ORDER BY `TestProductItem`.`id` asc LIMIT 25 Error: SQL Error: 1054: Unknown column 'TestType.description' in 'field list' [CORE/cake/libs/model/datasources/dbo_source.php, line 666] This is *expected* to be generated by cake, but is not: SELECT `TestProduct`.`title`, `TestType`.`description`, `TestProductItem`.`size`, COUNT(*) FROM `test_product_items` AS `TestProductItem` LEFT JOIN `test_products` AS `TestProduct` ON (`TestProductItem`.`test_product_id` = `TestProduct`.`id`) LEFT JOIN `test_types` AS `TestType` ON (`TestProduct`.`test_type_id` = `TestType`.`id`) WHERE 1 = 1 GROUP BY `TestProduct`.`id`, `TestProductItem`.`size` ORDER BY `TestProductItem`.`id` asc LIMIT 25 As you can see in first sql query, only join statement for test_products table is generated, but no for test_types. A. Below are source files: === controllers/test_product_items_controller.php === class TestProductItemsController extends AppController { var $paginate = array( 'limit' = 25, 'fields' = 'TestProduct.title, TestType.description, TestProductItem.size, COUNT(*)', 'order' = array( 'TestProductItem.id' = 'asc' ), 'group' = array( 'TestProduct.id, TestProductItem.size' ) ); function index() { $this-set('testProductItems', $this-paginate('TestProductItem')); } } === models/test_product.php === class TestProduct extends AppModel { var $belongsTo = array('TestType'); var $hasMany = array('TestProductItem'); } === models/test_type.php === class TestType extends AppModel { var $hasMany = array('TestProduct'); } === models/test_product_item.php === class TestProductItem extends AppModel { var $belongsTo = array('TestProduct'); } B. Database schema data: CREATE TABLE `test_products` ( `id` int(11) NOT NULL auto_increment, `title` varchar(128) NOT NULL, `test_type_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; CREATE TABLE `test_product_items` ( `id` int(11) NOT NULL auto_increment, `test_product_id` int(11) NOT NULL, `size` varchar(16) NOT NULL, `sold_time` datetime default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ; CREATE TABLE `test_types` ( `id` int(11) NOT NULL auto_increment, `description` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; INSERT INTO `test_products` VALUES (1, 'Star Jeans 502', 4); INSERT INTO `test_product_items` VALUES (7, 1, 'S', NULL); INSERT INTO `test_product_items` VALUES (8, 1, 'S', NULL); INSERT INTO `test_product_items` VALUES (9, 1, 'S', NULL); INSERT INTO `test_product_items` VALUES (10, 1, 'M', NULL); INSERT INTO `test_product_items` VALUES (11, 1, 'M', NULL); INSERT INTO `test_product_items` VALUES (12, 1, 'L', NULL); INSERT INTO `test_types` VALUES (4, 'Trousers'); Thanks in advance, T. On 27 Maj, 05:38, Jeremy Burns jeremybu...@me.com wrote: All of your table and field names should be lower case. What is your full find statement? Can you post it all, not just a small piece. Jeremy Burns jeremybu...@me.com On 27 May 2010, at 00:22, 朝の木 wrote: I have three models (with controllers): - Product: Id, Title, Type_id - Type: Id, Description - ProductItem: Id, Product_id, Size, Sold_time Relationships: - Product: belongsTo(Type), hasMany(ProductItem) - Type: hasMany(Product) - ProductItem: belongsTo(Product) Example: - Product: 1; 'Star Jeans 502', 4 (...) - Type: 4; 'Trousers' (...) - ProductItem: 7; 1; 'S', NULL 8; 1; 'S', NULL 9; 1; 'S', NULL 10; 1; 'M', NULL 11; 1; 'M', NULL 12; 1; 'L', NULL (...) Now, I'd like to fetch the in such way: Description, Type, Size, Count Star Jeans 502, 'Trousers', 'S', 3 Star Jeans 502, 'Trousers', 'M', 2 Star Jeans 502, 'Trousers', 'L', 1 The sql query should look like this: select Product.Title, Type.Description, ProductItem.Size, COUNT(ProductItem.*) left join Type on Product.Type_id = Type.id left join ProductItem on ProductItem.Product_id = Product.id group
Re: Problem with database cascade relationships.
Here is full statement *generated by cake*. It raises sql-error: SELECT `TestProduct`.`title`, `TestType`.`description`, `TestProductItem`.`size`, COUNT(*) FROM `test_product_items` AS `TestProductItem` LEFT JOIN `test_products` AS `TestProduct` ON (`TestProductItem`.`test_product_id` = `TestProduct`.`id`) WHERE 1 = 1 GROUP BY `TestProduct`.`id`, `TestProductItem`.`size` ORDER BY `TestProductItem`.`id` asc LIMIT 25 Error: SQL Error: 1054: Unknown column 'TestType.description' in 'field list' [CORE/cake/libs/model/datasources/dbo_source.php, line 666] This is *expected* to be generated by cake, but is not: SELECT `TestProduct`.`title`, `TestType`.`description`, `TestProductItem`.`size`, COUNT(*) FROM `test_product_items` AS `TestProductItem` LEFT JOIN `test_products` AS `TestProduct` ON (`TestProductItem`.`test_product_id` = `TestProduct`.`id`) LEFT JOIN `test_types` AS `TestType` ON (`TestProduct`.`test_type_id` = `TestType`.`id`) WHERE 1 = 1 GROUP BY `TestProduct`.`id`, `TestProductItem`.`size` ORDER BY `TestProductItem`.`id` asc LIMIT 25 As you can see in first sql query, only join statement for test_products table is generated, but no for test_types. A. Below are source files: === controllers/test_product_items_controller.php === class TestProductItemsController extends AppController { var $paginate = array( 'limit' = 25, 'fields' = 'TestProduct.title, TestType.description, TestProductItem.size, COUNT(*)', 'order' = array( 'TestProductItem.id' = 'asc' ), 'group' = array( 'TestProduct.id, TestProductItem.size' ) ); function index() { $this-set('testProductItems', $this-paginate('TestProductItem')); } } === models/test_product.php === class TestProduct extends AppModel { var $belongsTo = array('TestType'); var $hasMany = array('TestProductItem'); } === models/test_type.php === class TestType extends AppModel { var $hasMany = array('TestProduct'); } === models/test_product_item.php === class TestProductItem extends AppModel { var $belongsTo = array('TestProduct'); } B. Database schema data: CREATE TABLE `test_products` ( `id` int(11) NOT NULL auto_increment, `title` varchar(128) NOT NULL, `test_type_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; CREATE TABLE `test_product_items` ( `id` int(11) NOT NULL auto_increment, `test_product_id` int(11) NOT NULL, `size` varchar(16) NOT NULL, `sold_time` datetime default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ; CREATE TABLE `test_types` ( `id` int(11) NOT NULL auto_increment, `description` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; INSERT INTO `test_products` VALUES (1, 'Star Jeans 502', 4); INSERT INTO `test_product_items` VALUES (7, 1, 'S', NULL); INSERT INTO `test_product_items` VALUES (8, 1, 'S', NULL); INSERT INTO `test_product_items` VALUES (9, 1, 'S', NULL); INSERT INTO `test_product_items` VALUES (10, 1, 'M', NULL); INSERT INTO `test_product_items` VALUES (11, 1, 'M', NULL); INSERT INTO `test_product_items` VALUES (12, 1, 'L', NULL); INSERT INTO `test_types` VALUES (4, 'Trousers'); Thanks in advance, T. On 27 Maj, 05:38, Jeremy Burns jeremybu...@me.com wrote: All of your table and field names should be lower case. What is your full find statement? Can you post it all, not just a small piece. Jeremy Burns jeremybu...@me.com On 27 May 2010, at 00:22, 朝の木 wrote: I have three models (with controllers): - Product: Id, Title, Type_id - Type: Id, Description - ProductItem: Id, Product_id, Size, Sold_time Relationships: - Product: belongsTo(Type), hasMany(ProductItem) - Type: hasMany(Product) - ProductItem: belongsTo(Product) Example: - Product: 1; 'Star Jeans 502', 4 (...) - Type: 4; 'Trousers' (...) - ProductItem: 7; 1; 'S', NULL 8; 1; 'S', NULL 9; 1; 'S', NULL 10; 1; 'M', NULL 11; 1; 'M', NULL 12; 1; 'L', NULL (...) Now, I'd like to fetch the in such way: Description, Type, Size, Count Star Jeans 502, 'Trousers', 'S', 3 Star Jeans 502, 'Trousers', 'M', 2 Star Jeans 502, 'Trousers', 'L', 1 The sql query should look like this: select Product.Title, Type.Description, ProductItem.Size, COUNT(ProductItem.*) left join Type on Product.Type_id = Type.id left join ProductItem on ProductItem.Product_id = Product.id group by Product.Id, ProductItem.Size Is it correct? I want to make such sql in cakephp in automagicalled way using find in ProductItem controller. Unfortunately it does not work. I tried find with parameter: field = (Product.Title, Type.Description, ProductItem.Size, COUNT(ProductItem.*)) and group = (Product.Id, ProductItem.Size
Problem with database cascade relationships.
I have three models (with controllers): - Product: Id, Title, Type_id - Type: Id, Description - ProductItem: Id, Product_id, Size, Sold_time Relationships: - Product: belongsTo(Type), hasMany(ProductItem) - Type: hasMany(Product) - ProductItem: belongsTo(Product) Example: - Product: 1; 'Star Jeans 502', 4 (...) - Type: 4; 'Trousers' (...) - ProductItem: 7; 1; 'S', NULL 8; 1; 'S', NULL 9; 1; 'S', NULL 10; 1; 'M', NULL 11; 1; 'M', NULL 12; 1; 'L', NULL (...) Now, I'd like to fetch the in such way: Description, Type, Size, Count Star Jeans 502, 'Trousers', 'S', 3 Star Jeans 502, 'Trousers', 'M', 2 Star Jeans 502, 'Trousers', 'L', 1 The sql query should look like this: select Product.Title, Type.Description, ProductItem.Size, COUNT(ProductItem.*) left join Type on Product.Type_id = Type.id left join ProductItem on ProductItem.Product_id = Product.id group by Product.Id, ProductItem.Size Is it correct? I want to make such sql in cakephp in automagicalled way using find in ProductItem controller. Unfortunately it does not work. I tried find with parameter: field = (Product.Title, Type.Description, ProductItem.Size, COUNT(ProductItem.*)) and group = (Product.Id, ProductItem.Size), but cake doesn't want to put join on ProductType. I think that cake builds joins only for tables in relations with current model (ProductItem), and does not look deeper - belongsTo(Type) is defined in Product model. How to solve this problem? Kind regards, T. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Problem with database cascade relationships.
All of your table and field names should be lower case. What is your full find statement? Can you post it all, not just a small piece. Jeremy Burns jeremybu...@me.com On 27 May 2010, at 00:22, 朝の木 wrote: I have three models (with controllers): - Product: Id, Title, Type_id - Type: Id, Description - ProductItem: Id, Product_id, Size, Sold_time Relationships: - Product: belongsTo(Type), hasMany(ProductItem) - Type: hasMany(Product) - ProductItem: belongsTo(Product) Example: - Product: 1; 'Star Jeans 502', 4 (...) - Type: 4; 'Trousers' (...) - ProductItem: 7; 1; 'S', NULL 8; 1; 'S', NULL 9; 1; 'S', NULL 10; 1; 'M', NULL 11; 1; 'M', NULL 12; 1; 'L', NULL (...) Now, I'd like to fetch the in such way: Description, Type, Size, Count Star Jeans 502, 'Trousers', 'S', 3 Star Jeans 502, 'Trousers', 'M', 2 Star Jeans 502, 'Trousers', 'L', 1 The sql query should look like this: select Product.Title, Type.Description, ProductItem.Size, COUNT(ProductItem.*) left join Type on Product.Type_id = Type.id left join ProductItem on ProductItem.Product_id = Product.id group by Product.Id, ProductItem.Size Is it correct? I want to make such sql in cakephp in automagicalled way using find in ProductItem controller. Unfortunately it does not work. I tried find with parameter: field = (Product.Title, Type.Description, ProductItem.Size, COUNT(ProductItem.*)) and group = (Product.Id, ProductItem.Size), but cake doesn't want to put join on ProductType. I think that cake builds joins only for tables in relations with current model (ProductItem), and does not look deeper - belongsTo(Type) is defined in Product model. How to solve this problem? Kind regards, T. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
Glad to hear you were able to get that resolved. Check out the documentation for the Auth component http://book.cakephp.org/view/172/Authentication, in particular the user method http://book.cakephp.org/view/387/user. On Feb 24, 3:04 pm, deek derek.bon...@gmail.com wrote: Andy, It looks like the debug issue was the problem and everything is now working properly. My final question is this. Once a user is logged on (through the built-in Auth of CakePHP), what built-in functions should I use to determine that user's id number? For that matter what is a good way to test of a user is logged on or not? I ask because I would like some options/posts to be shown only to logged in (Admin) users. Currently this is my form for creating an new post: h1Add Post/h1 ?php echo $form-create('Post'); echo $form-input('title'); echo $form-input('category'); echo $form-input('body', array('rows' = '10', 'columns' = '40')); echo $form-radio('frontpage', array('1'='Yes','0'='No')); echo $form-end('Save Post'); ? I want to thank everyone who has helped out with my questions. On Feb 24, 7:21 am, Andy Dirnberger andy.dirnber...@gmail.com wrote: If you have debug set to 0 in core.php and added displayname to the user table after Cake first saw the it, you need to update the cache of the table's layout. (Either set debug to 1, reload the page, and set it back to 0 or delete the file in tmp.) On Feb 24, 2:36 am, deek derek.bon...@gmail.com wrote: Also when I try and add a user with this form h1Add User/h1 ?php echo $form-create('User', array('action' = 'register')); echo $form-input('username'); echo $form-input('displayname'); echo $form-input('password'); echo $form-end('Add User'); ? the displayname never makes it to the MySQL database. I have no idea why not On Feb 23, 11:27 pm, deek derek.bon...@gmail.com wrote: Well everything seems to be working now with var $belongsTo = array('User'); but I have tried putting ?php echo $post['User'] ['displayname']; ? in my index.ctp and the it does not output any of the information. If I put ?php echo $post['User']['id']; ? or ?php echo $post['User']['username']; ? those values will output just fine but not displayname, what might cause this? On Feb 23, 8:36 pm, Andy Dirnberger andy.dirnber...@gmail.com wrote: Did you try just using var $belongsTo = array('User');? The values you are supplying for className and foreignKey should be the defaults. If you remove the $belongsTo piece, do your posts show up again? If not, what else did you change? What code do you currently have in your controller? No special code is needed in your controller to handle relationships, and you'd only need to add code to your User model (e.g., var $hasMany = array('Post');) if you wanted posts to be retrieved every time you query your user table, which you probably don't. Once you have it working, 'User'] will be added as an index alongside 'Post' (e.g., $post['User']['displayname']). On Feb 23, 5:16 pm, deek derek.bon...@gmail.com wrote: So I updated my post model to what you see below and now when I go to my index (index.ctp) view that I have listed on my first post nothing shows up. Do I need to add anything in the controllers or the user model? Once get it to show properly how would I call the the User displayname in my foreach loop in the index.ctp? class Post extends AppModel { var $name = 'Post'; var $belongsTo = array ( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id' ) ); var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) );} On Feb 23, 12:01 am, WebbedIT p...@webbedit.co.uk wrote: ^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr
Re: Question about relationships, extending the blog tutorial
Can you show us the structure of your table? It seems Cake is not able to find that field. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
If you have debug set to 0 in core.php and added displayname to the user table after Cake first saw the it, you need to update the cache of the table's layout. (Either set debug to 1, reload the page, and set it back to 0 or delete the file in tmp.) On Feb 24, 2:36 am, deek derek.bon...@gmail.com wrote: Also when I try and add a user with this form h1Add User/h1 ?php echo $form-create('User', array('action' = 'register')); echo $form-input('username'); echo $form-input('displayname'); echo $form-input('password'); echo $form-end('Add User'); ? the displayname never makes it to the MySQL database. I have no idea why not On Feb 23, 11:27 pm, deek derek.bon...@gmail.com wrote: Well everything seems to be working now with var $belongsTo = array('User'); but I have tried putting ?php echo $post['User'] ['displayname']; ? in my index.ctp and the it does not output any of the information. If I put ?php echo $post['User']['id']; ? or ?php echo $post['User']['username']; ? those values will output just fine but not displayname, what might cause this? On Feb 23, 8:36 pm, Andy Dirnberger andy.dirnber...@gmail.com wrote: Did you try just using var $belongsTo = array('User');? The values you are supplying for className and foreignKey should be the defaults. If you remove the $belongsTo piece, do your posts show up again? If not, what else did you change? What code do you currently have in your controller? No special code is needed in your controller to handle relationships, and you'd only need to add code to your User model (e.g., var $hasMany = array('Post');) if you wanted posts to be retrieved every time you query your user table, which you probably don't. Once you have it working, 'User'] will be added as an index alongside 'Post' (e.g., $post['User']['displayname']). On Feb 23, 5:16 pm, deek derek.bon...@gmail.com wrote: So I updated my post model to what you see below and now when I go to my index (index.ctp) view that I have listed on my first post nothing shows up. Do I need to add anything in the controllers or the user model? Once get it to show properly how would I call the the User displayname in my foreach loop in the index.ctp? class Post extends AppModel { var $name = 'Post'; var $belongsTo = array ( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id' ) ); var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) );} On Feb 23, 12:01 am, WebbedIT p...@webbedit.co.uk wrote: ^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
Andy, It looks like the debug issue was the problem and everything is now working properly. My final question is this. Once a user is logged on (through the built-in Auth of CakePHP), what built-in functions should I use to determine that user's id number? For that matter what is a good way to test of a user is logged on or not? I ask because I would like some options/posts to be shown only to logged in (Admin) users. Currently this is my form for creating an new post: h1Add Post/h1 ?php echo $form-create('Post'); echo $form-input('title'); echo $form-input('category'); echo $form-input('body', array('rows' = '10', 'columns' = '40')); echo $form-radio('frontpage', array('1'='Yes','0'='No')); echo $form-end('Save Post'); ? I want to thank everyone who has helped out with my questions. On Feb 24, 7:21 am, Andy Dirnberger andy.dirnber...@gmail.com wrote: If you have debug set to 0 in core.php and added displayname to the user table after Cake first saw the it, you need to update the cache of the table's layout. (Either set debug to 1, reload the page, and set it back to 0 or delete the file in tmp.) On Feb 24, 2:36 am, deek derek.bon...@gmail.com wrote: Also when I try and add a user with this form h1Add User/h1 ?php echo $form-create('User', array('action' = 'register')); echo $form-input('username'); echo $form-input('displayname'); echo $form-input('password'); echo $form-end('Add User'); ? the displayname never makes it to the MySQL database. I have no idea why not On Feb 23, 11:27 pm, deek derek.bon...@gmail.com wrote: Well everything seems to be working now with var $belongsTo = array('User'); but I have tried putting ?php echo $post['User'] ['displayname']; ? in my index.ctp and the it does not output any of the information. If I put ?php echo $post['User']['id']; ? or ?php echo $post['User']['username']; ? those values will output just fine but not displayname, what might cause this? On Feb 23, 8:36 pm, Andy Dirnberger andy.dirnber...@gmail.com wrote: Did you try just using var $belongsTo = array('User');? The values you are supplying for className and foreignKey should be the defaults. If you remove the $belongsTo piece, do your posts show up again? If not, what else did you change? What code do you currently have in your controller? No special code is needed in your controller to handle relationships, and you'd only need to add code to your User model (e.g., var $hasMany = array('Post');) if you wanted posts to be retrieved every time you query your user table, which you probably don't. Once you have it working, 'User'] will be added as an index alongside 'Post' (e.g., $post['User']['displayname']). On Feb 23, 5:16 pm, deek derek.bon...@gmail.com wrote: So I updated my post model to what you see below and now when I go to my index (index.ctp) view that I have listed on my first post nothing shows up. Do I need to add anything in the controllers or the user model? Once get it to show properly how would I call the the User displayname in my foreach loop in the index.ctp? class Post extends AppModel { var $name = 'Post'; var $belongsTo = array ( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id' ) ); var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) );} On Feb 23, 12:01 am, WebbedIT p...@webbedit.co.uk wrote: ^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
So I updated my post model to what you see below and now when I go to my index (index.ctp) view that I have listed on my first post nothing shows up. Do I need to add anything in the controllers or the user model? Once get it to show properly how would I call the the User displayname in my foreach loop in the index.ctp? class Post extends AppModel { var $name = 'Post'; var $belongsTo = array ( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id' ) ); var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) ); } On Feb 23, 12:01 am, WebbedIT p...@webbedit.co.uk wrote: ^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
Did you try just using var $belongsTo = array('User');? The values you are supplying for className and foreignKey should be the defaults. If you remove the $belongsTo piece, do your posts show up again? If not, what else did you change? What code do you currently have in your controller? No special code is needed in your controller to handle relationships, and you'd only need to add code to your User model (e.g., var $hasMany = array('Post');) if you wanted posts to be retrieved every time you query your user table, which you probably don't. Once you have it working, 'User'] will be added as an index alongside 'Post' (e.g., $post['User']['displayname']). On Feb 23, 5:16 pm, deek derek.bon...@gmail.com wrote: So I updated my post model to what you see below and now when I go to my index (index.ctp) view that I have listed on my first post nothing shows up. Do I need to add anything in the controllers or the user model? Once get it to show properly how would I call the the User displayname in my foreach loop in the index.ctp? class Post extends AppModel { var $name = 'Post'; var $belongsTo = array ( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id' ) ); var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) );} On Feb 23, 12:01 am, WebbedIT p...@webbedit.co.uk wrote: ^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
Well everything seems to be working now with var $belongsTo = array('User'); but I have tried putting ?php echo $post['User'] ['displayname']; ? in my index.ctp and the it does not output any of the information. If I put ?php echo $post['User']['id']; ? or ?php echo $post['User']['username']; ? those values will output just fine but not displayname, what might cause this? On Feb 23, 8:36 pm, Andy Dirnberger andy.dirnber...@gmail.com wrote: Did you try just using var $belongsTo = array('User');? The values you are supplying for className and foreignKey should be the defaults. If you remove the $belongsTo piece, do your posts show up again? If not, what else did you change? What code do you currently have in your controller? No special code is needed in your controller to handle relationships, and you'd only need to add code to your User model (e.g., var $hasMany = array('Post');) if you wanted posts to be retrieved every time you query your user table, which you probably don't. Once you have it working, 'User'] will be added as an index alongside 'Post' (e.g., $post['User']['displayname']). On Feb 23, 5:16 pm, deek derek.bon...@gmail.com wrote: So I updated my post model to what you see below and now when I go to my index (index.ctp) view that I have listed on my first post nothing shows up. Do I need to add anything in the controllers or the user model? Once get it to show properly how would I call the the User displayname in my foreach loop in the index.ctp? class Post extends AppModel { var $name = 'Post'; var $belongsTo = array ( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id' ) ); var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) );} On Feb 23, 12:01 am, WebbedIT p...@webbedit.co.uk wrote: ^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
Also when I try and add a user with this form h1Add User/h1 ?php echo $form-create('User', array('action' = 'register')); echo $form-input('username'); echo $form-input('displayname'); echo $form-input('password'); echo $form-end('Add User'); ? the displayname never makes it to the MySQL database. I have no idea why not On Feb 23, 11:27 pm, deek derek.bon...@gmail.com wrote: Well everything seems to be working now with var $belongsTo = array('User'); but I have tried putting ?php echo $post['User'] ['displayname']; ? in my index.ctp and the it does not output any of the information. If I put ?php echo $post['User']['id']; ? or ?php echo $post['User']['username']; ? those values will output just fine but not displayname, what might cause this? On Feb 23, 8:36 pm, Andy Dirnberger andy.dirnber...@gmail.com wrote: Did you try just using var $belongsTo = array('User');? The values you are supplying for className and foreignKey should be the defaults. If you remove the $belongsTo piece, do your posts show up again? If not, what else did you change? What code do you currently have in your controller? No special code is needed in your controller to handle relationships, and you'd only need to add code to your User model (e.g., var $hasMany = array('Post');) if you wanted posts to be retrieved every time you query your user table, which you probably don't. Once you have it working, 'User'] will be added as an index alongside 'Post' (e.g., $post['User']['displayname']). On Feb 23, 5:16 pm, deek derek.bon...@gmail.com wrote: So I updated my post model to what you see below and now when I go to my index (index.ctp) view that I have listed on my first post nothing shows up. Do I need to add anything in the controllers or the user model? Once get it to show properly how would I call the the User displayname in my foreach loop in the index.ctp? class Post extends AppModel { var $name = 'Post'; var $belongsTo = array ( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id' ) ); var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) );} On Feb 23, 12:01 am, WebbedIT p...@webbedit.co.uk wrote: ^^ What @Andy says is right. Simple rule of thumb for hasMany/hasOne - belongsTo relationships ... whichever model your foreign_key is in, it belongs to the other model. Welcome to CakePHP, it should make learning complex PHP a lot easier for you. I sometimes wish I hadn't taught myself a lot of bad habits by learning raw PHP first :) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Question about relationships, extending the blog tutorial
First of all let me say I'm very new to CakePHP and complex PHP in general. I based the blog I am working on off the tutorial on the CakePHP website. I skipped creating ACL or a more complex management of permissions because as of now the only people who will be posting content will be Authorized users so using the Auth component in both of my controllers with an appropriate beforeFilter() function has done exactly what I needed. What I am trying to do is in my display of posted articles have $post['Post']['user_id']; look up the in the users post table the display name, I haven't found a simple answer for this so that is why I am posting. I've looked through the cakePHP book online and thought I might need to do something to link models together but I didn't have any success with that. I tried having the Post model include var $hasOne = User but that ended up breaking everything. Any suggestions would be greatly appreciated. Below are my table structures, models, and view I am working with -- Table structure for table `posts` CREATE TABLE IF NOT EXISTS `posts` ( `id` int(10) unsigned NOT NULL auto_increment, `user_id` int(11) NOT NULL, `title` varchar(50) default NULL, `category` varchar(50) default NULL, `body` text, `frontpage` tinyint(1) NOT NULL, `created` datetime default NULL, `modified` datetime default NULL, PRIMARY KEY (`id`) ) -- Table structure for table `users` CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL auto_increment, `username` char(50) default NULL, `password` char(40) default NULL, `displayname` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) Post Model: class Post extends AppModel { var $name = 'Post'; var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) ); } User model: class User extends AppModel { var $name = 'User'; var $validate = array( 'username' = array( 'rule' = 'notEmpty', 'message' = 'Please enter your Username' ), 'displayname' = array( 'rule' = 'notEmpty' 'message' = 'Please enter the name you wish displayed with your posts' ), 'password' = array( 'rule' = 'notEmpty', 'message' = 'Pelase enter your Password' ) ); } index.ctp: This view is on my main page and loops through all the posts that are tagged to be on the front page ?php foreach (array_reverse($posts) as $post){if ($post['Post'] ['frontpage']==true){ ? ?php echo $html-link($post['Post']['title'], array('controller' = 'posts', 'action' = 'view', $post['Post'] ['id'])); ?br/ ?php echo $post['Post']['category']; ?br/ ?php echo $post['Post']['created']; ?br/ ?php echo $post['Post']['body']; ?br/ ?php echo $post['Post']['user_id']; ?br/br/ ?php }}; ? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question about relationships, extending the blog tutorial
Try $belongsTo instead of $hasOne. $belongsTo = array('User'); On Feb 22, 7:03 pm, deek derek.bon...@gmail.com wrote: First of all let me say I'm very new to CakePHP and complex PHP in general. I based the blog I am working on off the tutorial on the CakePHP website. I skipped creating ACL or a more complex management of permissions because as of now the only people who will be posting content will be Authorized users so using the Auth component in both of my controllers with an appropriate beforeFilter() function has done exactly what I needed. What I am trying to do is in my display of posted articles have $post['Post']['user_id']; look up the in the users post table the display name, I haven't found a simple answer for this so that is why I am posting. I've looked through the cakePHP book online and thought I might need to do something to link models together but I didn't have any success with that. I tried having the Post model include var $hasOne = User but that ended up breaking everything. Any suggestions would be greatly appreciated. Below are my table structures, models, and view I am working with -- Table structure for table `posts` CREATE TABLE IF NOT EXISTS `posts` ( `id` int(10) unsigned NOT NULL auto_increment, `user_id` int(11) NOT NULL, `title` varchar(50) default NULL, `category` varchar(50) default NULL, `body` text, `frontpage` tinyint(1) NOT NULL, `created` datetime default NULL, `modified` datetime default NULL, PRIMARY KEY (`id`) ) -- Table structure for table `users` CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL auto_increment, `username` char(50) default NULL, `password` char(40) default NULL, `displayname` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) Post Model: class Post extends AppModel { var $name = 'Post'; var $validate = array ( 'title' = array( 'rule' = 'notEmpty' ), 'category' = array( 'rule' = 'notEmpty' ), 'body' = array( 'rule' = 'notEmpty' ), 'frontpage' = array( 'rule' = 'numeric' ) );} User model: class User extends AppModel { var $name = 'User'; var $validate = array( 'username' = array( 'rule' = 'notEmpty', 'message' = 'Please enter your Username' ), 'displayname' = array( 'rule' = 'notEmpty' 'message' = 'Please enter the name you wish displayed with your posts' ), 'password' = array( 'rule' = 'notEmpty', 'message' = 'Pelase enter your Password' ) );} index.ctp: This view is on my main page and loops through all the posts that are tagged to be on the front page ?php foreach (array_reverse($posts) as $post){if ($post['Post'] ['frontpage']==true){ ? ?php echo $html-link($post['Post']['title'], array('controller' = 'posts', 'action' = 'view', $post['Post'] ['id'])); ?br/ ?php echo $post['Post']['category']; ?br/ ?php echo $post['Post']['created']; ?br/ ?php echo $post['Post']['body']; ?br/ ?php echo $post['Post']['user_id']; ?br/br/ ?php }}; ? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to setup relationships in model User has a Status
AFAIK, In general we have three statuses for every account created but not active (0) activated (1) banned (-1) It is better to stick to one table (users), so this table have an indexed integer field called status. As for Active, ''Banned, etc... It is just a convention and 9X% of the queries around the users table do not need those strings. just because I don't want to say 100% (because I hate the number 100) On Dec 28, 1:24 am, Brettski brettsk...@gmail.com wrote: Hi, Just learning CakePHP now. I have a simple question, hopefully its a simple answer :) I'm trying to get my models setup right, so I have a user model, and a status model, for example.. Status = Active or Cancelled etc. I can't seem to get the associations right. How do you set each of these up so that I return an array of status's to the user model. I thought it would be User hasOne Status, Status hasMany Users but that doesn't work, it looks for a Status.user_id which isn't a field (as it doesn't make sense). b Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Complex Relationships
Hi, I need some guidance on how to build these model relationships. I need to build something that allows people to book a room in an accommodation. These are the steps. User finds room. User requests to stay in room Owner accepts / declines User Pays / finds another room. I have 3 tables so far. Members, Accommodations, BookingRequests At the moment I have the foreign key member_id in Accommodation. Do I need to add it to BookingRequest as well? This is what I store in each. Members id,email,password Accommodation id,member_id,title,room_type,price,price_week,price_month BookingRequests id,accommodation_id,checkin_date,checkout_date,message,read,member_id The relationships are. Members hasMany Accommodation Accommodation hasMany BookingRequest, belongsTo Member BookingRequest belongsTo Accommodation. Any suggestions? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Complex Relationships
I see the following objects in your description: Renter, Guest, Room, Owner, Booking Can one room have more than one Guest per room? Can one booking involve more than one room? John On Dec 2, 5:42 pm, onlymejosh star...@gmail.com wrote: Hi, I need some guidance on how to build these model relationships. I need to build something that allows people to book a room in an accommodation. These are the steps. User finds room. User requests to stay in room Owner accepts / declines User Pays / finds another room. I have 3 tables so far. Members, Accommodations, BookingRequests At the moment I have the foreign key member_id in Accommodation. Do I need to add it to BookingRequest as well? This is what I store in each. Members id,email,password Accommodation id,member_id,title,room_type,price,price_week,price_month BookingRequests id,accommodation_id,checkin_date,checkout_date,message,read,member_id The relationships are. Members hasMany Accommodation Accommodation hasMany BookingRequest, belongsTo Member BookingRequest belongsTo Accommodation. Any suggestions? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Complex Relationships
These are the objects Renter, Owner, Room, Booking The number of guests isn't a factor. The booking invovles one room at a time. Its not a normal hotel per- say On Dec 2, 5:18 pm, John Andersen j.andersen...@gmail.com wrote: I see the following objects in your description: Renter, Guest, Room, Owner, Booking Can one room have more than one Guest per room? Can one booking involve more than one room? John On Dec 2, 5:42 pm, onlymejosh star...@gmail.com wrote: Hi, I need some guidance on how to build these model relationships. I need to build something that allows people to book a room in an accommodation. These are the steps. User finds room. User requests to stay in room Owner accepts / declines User Pays / finds another room. I have 3 tables so far. Members, Accommodations, BookingRequests At the moment I have the foreign key member_id in Accommodation. Do I need to add it to BookingRequest as well? This is what I store in each. Members id,email,password Accommodation id,member_id,title,room_type,price,price_week,price_month BookingRequests id,accommodation_id,checkin_date,checkout_date,message,read,member_id The relationships are. Members hasMany Accommodation Accommodation hasMany BookingRequest, belongsTo Member BookingRequest belongsTo Accommodation. Any suggestions? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Complex Relationships
Ok :) Using your terms, the following may be defined: Owner hasMany Location, Location belongsTo Owner Location hasMany Room, Room belongsTo Location Category hasMany Room, Room belongsTo Category Room hasMany Booking, Booking belongsTo Room Renter hasMany Booking, Booking belongsTo Renter Where: Owner owns one or more locations, each with one or more rooms. Location is a building, a camping field, whatever Category gives the basic information on each room Room defines a bookable room in a location Renter makes a booking of a room. Booking defines the actual request for a room. Booking also is used for tracking the reply from the owner (status field) and final price (price settled, price_type). Database schema would be something like: Booking (id, room_id, renter_id, arrival, departure, status, message, price_type, price_settled, created, modified) Location (id, owner_id, address, created) Category (id, name, price_daily, price_weekly, price_forthnight, price_monthly, occupants, created) Room (id, location_id, category_id, description, created) Well, the above is only ideas, so take what you can use! Probably you also need something in which to track that the payment has been made. Enjoy, John On Dec 2, 10:31 pm, onlymejosh star...@gmail.com wrote: These are the objects Renter, Owner, Room, Booking The number of guests isn't a factor. The booking invovles one room at a time. Its not a normal hotel per- say On Dec 2, 5:18 pm, John Andersen j.andersen...@gmail.com wrote: I see the following objects in your description: Renter, Guest, Room, Owner, Booking Can one room have more than one Guest per room? Can one booking involve more than one room? John On Dec 2, 5:42 pm, onlymejosh star...@gmail.com wrote: Hi, I need some guidance on how to build these model relationships. I need to build something that allows people to book a room in an accommodation. These are the steps. User finds room. User requests to stay in room Owner accepts / declines User Pays / finds another room. I have 3 tables so far. Members, Accommodations, BookingRequests At the moment I have the foreign key member_id in Accommodation. Do I need to add it to BookingRequest as well? This is what I store in each. Members id,email,password Accommodation id,member_id,title,room_type,price,price_week,price_month BookingRequests id,accommodation_id,checkin_date,checkout_date,message,read,member_id The relationships are. Members hasMany Accommodation Accommodation hasMany BookingRequest, belongsTo Member BookingRequest belongsTo Accommodation. Any suggestions? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Question Concerning Nested Relationships
Use the Containable behavior : http://book.cakephp.org/view/474/Containable On Wed, Oct 21, 2009 at 7:32 PM, Andrew and...@websitesthatdostuff.comwrote: I've got a Post model set up that has a BelongsTo relationship to a Group model. This Group is related by HABTM to 1+ Media models. The Post model has other BelongsTo and HABTM relationships to other classes. What I'd like to do is in the Post model retrieve the Media models related to it through the Group model without retrieving any more of the other relationships in the Post model. In other words, I'd like to set recursive=2 for the Group model and recursive=1 for other relationships. What's the best way to do this? Thanks! ~Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Question Concerning Nested Relationships
Nice! Thanks a lot. On Oct 22, 3:20 am, Bert Van den Brande cyr...@gmail.com wrote: Use the Containable behavior :http://book.cakephp.org/view/474/Containable On Wed, Oct 21, 2009 at 7:32 PM, Andrew and...@websitesthatdostuff.comwrote: I've got a Post model set up that has a BelongsTo relationship to a Group model. This Group is related by HABTM to 1+ Media models. The Post model has other BelongsTo and HABTM relationships to other classes. What I'd like to do is in the Post model retrieve the Media models related to it through the Group model without retrieving any more of the other relationships in the Post model. In other words, I'd like to set recursive=2 for the Group model and recursive=1 for other relationships. What's the best way to do this? Thanks! ~Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Question Concerning Nested Relationships
I've got a Post model set up that has a BelongsTo relationship to a Group model. This Group is related by HABTM to 1+ Media models. The Post model has other BelongsTo and HABTM relationships to other classes. What I'd like to do is in the Post model retrieve the Media models related to it through the Group model without retrieving any more of the other relationships in the Post model. In other words, I'd like to set recursive=2 for the Group model and recursive=1 for other relationships. What's the best way to do this? Thanks! ~Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
model relationships and retrieve data at runtime
Hi, I have a model with a $belongsTo and a $hasMany relations. My question is: is there a way to decide at RUNTIME when load or not load related model data? I have an index method in my controller where I need only my parent model data and then a view/id method where I need also the related model data. Is that clear? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: model relationships and retrieve data at runtime
Use 'recursive' or 'contain' params in your find() calls. On Thu, Sep 17, 2009 at 8:17 AM, DierRe die...@gmail.com wrote: Hi, I have a model with a $belongsTo and a $hasMany relations. My question is: is there a way to decide at RUNTIME when load or not load related model data? I have an index method in my controller where I need only my parent model data and then a view/id method where I need also the related model data. Is that clear? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: model relationships and retrieve data at runtime
Ok let me explain my real example so you can understand me better (BTW 'contain' is not in the cookbook I think). I have ParentModel, Child1Model and Child2Model. They're both $hasMany. What can I do to show only Child1Model? Do I use 'contain'? On 17 Set, 18:37, brian bally.z...@gmail.com wrote: Use 'recursive' or 'contain' params in your find() calls. On Thu, Sep 17, 2009 at 8:17 AM, DierRe die...@gmail.com wrote: Hi, I have a model with a $belongsTo and a $hasMany relations. My question is: is there a way to decide at RUNTIME when load or not load related model data? I have an index method in my controller where I need only my parent model data and then a view/id method where I need also the related model data. Is that clear? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: model relationships and retrieve data at runtime
$this-ParentModel-find( 'all', array( 'conditions' = array(...), 'contain' = array('Child1Model') ) ); That will cause Cake to effectively set recursive to -1 BUT grab just the Child1Model data. On Thu, Sep 17, 2009 at 2:55 PM, DierRe die...@gmail.com wrote: Ok let me explain my real example so you can understand me better (BTW 'contain' is not in the cookbook I think). I have ParentModel, Child1Model and Child2Model. They're both $hasMany. What can I do to show only Child1Model? Do I use 'contain'? On 17 Set, 18:37, brian bally.z...@gmail.com wrote: Use 'recursive' or 'contain' params in your find() calls. On Thu, Sep 17, 2009 at 8:17 AM, DierRe die...@gmail.com wrote: Hi, I have a model with a $belongsTo and a $hasMany relations. My question is: is there a way to decide at RUNTIME when load or not load related model data? I have an index method in my controller where I need only my parent model data and then a view/id method where I need also the related model data. Is that clear? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Master Filter for HABTM-Relationships
This brought the solution: http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find Marco --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---