Re: HABTM problem for help
Hi Stephen, Thank you very much for your kindly help. 2011/3/5 Stephen step...@ninjacodermonkey.co.uk Hi There From the cookbook: *With HABTM, you need to set the ID of the associated model in your data array. We'll build a form that creates a new tag and associates it on the fly with some recipe.* [1] Try doing User.id not User.username [1] http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM#!/view/1034/Saving-Related-Model-Data-HABTM On 5 March 2011 07:18, Ekin Han nbkhic...@gmail.com wrote: Hi all, I have such a problem about HABTM. I have 3 tables, users table, bugs table and bugs_users table. The relation ship between users and bugs are just like below: users HABTM bugs bugs HABTM users Now I write a method in Bugs controller which name add() just like below function add(){ if(!empty($this-data)){ debug($this-data); die; $this-Bug-create(); if($this-Bug-Save($this-data)){ $this-Session-setFlash(__('Create Successfully', true)); $this-redirect(array('action' = 'index')); } else{ $this-Session-setFlash(t('Can Not create bug', true)); } } } And the add.ctp is just like below: h3Create Bug/h3 ?php echo $form-create('Bug', array('action' = 'add')); echo $form-input('title'); echo $form-input('description'); echo $form-input('User.username'); echo $form-end('Submit'); ? I have a problem that when a new bug was add ,the table bugs_uses has nothing new in it. Shall I need to write a record to it myself? That means cake do not automaticly write a record the the relation table? -- 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 -- Kind Regards Stephen http://www.ninjacodermonkey.co.uk -- 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
HABTM problem for help
Hi all, I have such a problem about HABTM. I have 3 tables, users table, bugs table and bugs_users table. The relation ship between users and bugs are just like below: users HABTM bugs bugs HABTM users Now I write a method in Bugs controller which name add() just like below function add(){ if(!empty($this-data)){ debug($this-data); die; $this-Bug-create(); if($this-Bug-Save($this-data)){ $this-Session-setFlash(__('Create Successfully', true)); $this-redirect(array('action' = 'index')); } else{ $this-Session-setFlash(t('Can Not create bug', true)); } } } And the add.ctp is just like below: h3Create Bug/h3 ?php echo $form-create('Bug', array('action' = 'add')); echo $form-input('title'); echo $form-input('description'); echo $form-input('User.username'); echo $form-end('Submit'); ? I have a problem that when a new bug was add ,the table bugs_uses has nothing new in it. Shall I need to write a record to it myself? That means cake do not automaticly write a record the the relation table? -- 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: HABTM problem for help
Hi There From the cookbook: *With HABTM, you need to set the ID of the associated model in your data array. We'll build a form that creates a new tag and associates it on the fly with some recipe.* [1] Try doing User.id not User.username [1] http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM#!/view/1034/Saving-Related-Model-Data-HABTM On 5 March 2011 07:18, Ekin Han nbkhic...@gmail.com wrote: Hi all, I have such a problem about HABTM. I have 3 tables, users table, bugs table and bugs_users table. The relation ship between users and bugs are just like below: users HABTM bugs bugs HABTM users Now I write a method in Bugs controller which name add() just like below function add(){ if(!empty($this-data)){ debug($this-data); die; $this-Bug-create(); if($this-Bug-Save($this-data)){ $this-Session-setFlash(__('Create Successfully', true)); $this-redirect(array('action' = 'index')); } else{ $this-Session-setFlash(t('Can Not create bug', true)); } } } And the add.ctp is just like below: h3Create Bug/h3 ?php echo $form-create('Bug', array('action' = 'add')); echo $form-input('title'); echo $form-input('description'); echo $form-input('User.username'); echo $form-end('Submit'); ? I have a problem that when a new bug was add ,the table bugs_uses has nothing new in it. Shall I need to write a record to it myself? That means cake do not automaticly write a record the the relation table? -- 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 -- Kind Regards Stephen http://www.ninjacodermonkey.co.uk -- 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
any body please help me with HABTM problem, please...
Hi, everyone, I am a newbie to cakephp, I am learning the HABTM, and try to see the post tag example working with the $scaffold. I have added the $hasAndBelongsToMany in both model files, but when I open the /blog/posts/add, I can never see the tags with the scaffolding. So frustrating... I know I must have made some stupid mistake, anyone could shed some light for me? I am attaching the two model files, two controller files and the sql database file in this link: http://www.excelsrmc.com/myFile/HABTM_files.rar Any help is really appreciated. Thanks again! -- 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: Quick habtm problem
How about using WITH in the Judge-Model? Is this a good way to do it? class Judges extends AppModel { var $name = Judge; var $hasAndBelongsToMany = array(MediaSegments = array(with = JudgesMediaSegments)); } On 15 Apr., 02:37, Bryan Paddock bryanpadd...@gmail.com wrote: Ah! Thank you! After a while of tinkering with your code I realised I had the $actsAs in the controller and not the model :( Works like a charm. I've modified all of my code now to use containable behaviour. Gone with recursive = -1. On Wed, Apr 14, 2010 at 3:45 PM, Jeremy Burns jeremybu...@me.com wrote: Are you using Containable behaviour? You should be! Try this...(typed without testing - so go easy on me if it's wrong!)... From the MediaSegment controller: $this-MediaSegment-find( 'all', array( 'contain' = array( 'Judge' ), 'conditions' =array( 'MediaSegment.id' = $id ) ) ); From the judges controller: $this-Judge-MediaSegment-find( 'all', array( 'contain' = array( 'Judge' ), 'conditions' =array( 'MediaSegment.id' = $id ) ) ); From within a model, just omit the first Model in the find statement (so $this-find()) Jeremy Burns jeremybu...@me.com jeremybu...@mac.com On 14 Apr 2010, at 14:37, Bryan Paddock wrote: Hey all, Going a bit crazy here I think I need a break from this. Anyways, I have the following tables + relationships Judges MediaSegments (a category that the judge is selected to judge) JudgesMediaSegments (contains judge_id and media_segment_id) How would I find all the judges that belong to a specific media segment? I know its something really simple I just cannot seem to get it right. Thanks 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 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.comcake-php%2bunsubscr...@googlegroups.comFor 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 To unsubscribe, reply using remove me as the subject.
Quick habtm problem
Hey all, Going a bit crazy here I think I need a break from this. Anyways, I have the following tables + relationships Judges MediaSegments (a category that the judge is selected to judge) JudgesMediaSegments (contains judge_id and media_segment_id) How would I find all the judges that belong to a specific media segment? I know its something really simple I just cannot seem to get it right. Thanks 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 To unsubscribe, reply using remove me as the subject.
Re: Quick habtm problem
Are you using Containable behaviour? You should be! Try this...(typed without testing - so go easy on me if it's wrong!)... From the MediaSegment controller: $this-MediaSegment-find( 'all', array( 'contain' = array( 'Judge' ), 'conditions' =array( 'MediaSegment.id' = $id ) ) ); From the judges controller: $this-Judge-MediaSegment-find( 'all', array( 'contain' = array( 'Judge' ), 'conditions' =array( 'MediaSegment.id' = $id ) ) ); From within a model, just omit the first Model in the find statement (so $this-find()) Jeremy Burns jeremybu...@me.com On 14 Apr 2010, at 14:37, Bryan Paddock wrote: Hey all, Going a bit crazy here I think I need a break from this. Anyways, I have the following tables + relationships Judges MediaSegments (a category that the judge is selected to judge) JudgesMediaSegments (contains judge_id and media_segment_id) How would I find all the judges that belong to a specific media segment? I know its something really simple I just cannot seem to get it right. Thanks 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 To unsubscribe, reply using remove me as the subject.
Re: Quick habtm problem
Ah! Thank you! After a while of tinkering with your code I realised I had the $actsAs in the controller and not the model :( Works like a charm. I've modified all of my code now to use containable behaviour. Gone with recursive = -1. On Wed, Apr 14, 2010 at 3:45 PM, Jeremy Burns jeremybu...@me.com wrote: Are you using Containable behaviour? You should be! Try this...(typed without testing - so go easy on me if it's wrong!)... From the MediaSegment controller: $this-MediaSegment-find( 'all', array( 'contain' = array( 'Judge' ), 'conditions' =array( 'MediaSegment.id' = $id ) ) ); From the judges controller: $this-Judge-MediaSegment-find( 'all', array( 'contain' = array( 'Judge' ), 'conditions' =array( 'MediaSegment.id' = $id ) ) ); From within a model, just omit the first Model in the find statement (so $this-find()) Jeremy Burns jeremybu...@me.com jeremybu...@mac.com On 14 Apr 2010, at 14:37, Bryan Paddock wrote: Hey all, Going a bit crazy here I think I need a break from this. Anyways, I have the following tables + relationships Judges MediaSegments (a category that the judge is selected to judge) JudgesMediaSegments (contains judge_id and media_segment_id) How would I find all the judges that belong to a specific media segment? I know its something really simple I just cannot seem to get it right. Thanks 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.comcake-php%2bunsubscr...@googlegroups.comFor 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 To unsubscribe, reply using remove me as the subject.
Re: HABTM problem...
Contain does do extra queries and then merges arrays back together. It's great for certain situations and not so great for others. I particularly like to use it when viewing records and associated data, but I'm not so keen within indexes/lists of data. Bind and unbind allow you to force joins to get data in one call which also allows you to sort results by fields from associated models. Glad you got it working :) --~--~-~--~~~---~--~~ 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: HABTM problem...
Try using contain and doing a $result = $this-Playlist-find('first', array( 'conditions'=array('Playlist.id'=$id), 'contain'=array('Song'=array('Artist','Album')) )); Then do an echo debug($result); to see what it's fetched and how the array is structured. --~--~-~--~~~---~--~~ 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: HABTM problem...
I beware of using contain, 'cause I don't understand how it works yet. I know that at least some times it runs multiple queries to achieve it's goal. Thanks for the tip though. After fighting with that thing for some time I did some unbind/bind models. And got the result with single query at last. On Oct 25, 11:52 am, WebbedIT p...@webbedit.co.uk wrote: Try using contain and doing a $result = $this-Playlist-find('first', array( 'conditions'=array('Playlist.id'=$id), 'contain'=array('Song'=array('Artist','Album')) )); Then do an echo debug($result); to see what it's fetched and how the array is structured. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
HABTM problem...
Let's say I've got table Playlists and table Songs (this one has it's own associations with Artists, Albums, etc.) that obvously got HABTM association (all tables are named properly, according to Cake conventions). Now the question (probably it's very dumb, sorry :) I got HABTM association between Playlists and Songs, and only HABTM, is it enough to use $this-Song-find() method to find all songs that correspond to a specific playlist (I do provide all necessary conditions)? The problem is that having all that in place I see that cake doesn't join HABTM associated tables in this case. Do they have to have other associations to? hasOne? hasMany? --~--~-~--~~~---~--~~ 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: HABTM problem...
I will rephrase a bit. As I said I have table Playlists and table Songs (this one has it's own associations with Artists, Albums tables, etc.) that obviously got HABTM association (all tables are named properly, according to Cake conventions). Now, how do I retrieve all songs, with all the artist, album data, that belong to a particular playlist? On Oct 24, 2:26 pm, jayarjo jaya...@gmail.com wrote: Let's say I've got table Playlists and table Songs (this one has it's own associations with Artists, Albums, etc.) that obvously got HABTM association (all tables are named properly, according to Cake conventions). Now the question (probably it's very dumb, sorry :) I got HABTM association between Playlists and Songs, and only HABTM, is it enough to use $this-Song-find() method to find all songs that correspond to a specific playlist (I do provide all necessary conditions)? The problem is that having all that in place I see that cake doesn't join HABTM associated tables in this case. Do they have to have other associations to? hasOne? hasMany? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
find with HABTM problem
hi peoples, i have two models is cakephp: class Pessoa extends AppModel { var $name = 'Pessoa'; var $primaryKey = 'codigo'; var $hasAndBelongsToMany = array( 'Areainteresse' = array( 'className'= 'Areainteresse', 'joinTable' = 'areainteressepessoa', 'foreignKey' = 'codigopessoa', 'associationForeignKey' = 'codigoareainteresse' ) ); } and class Areainteresse extends AppModel { var $name = 'Areainteresse'; var $useTable = 'areainteresse'; var $primaryKey = 'codigo'; } when i run the $this-Pessoa-find(). he return me: array(2) { [0]= array(12) { [codigo]= int(6) } [Areainteresse]= array(0) { } } the Pessoa entity is returned normally, however the entity Areainteresse not returned. This only for the find(). the save() work normally. The data are in the table correctly. Anyone have any solution? --- Wladiston Maurício de Paiva http://wladistonpaiva.com.br desenvolvedo...@gmail.com e...@wladistonpaiva.com.br +55 (31) 8435 - 5380 --~--~-~--~~~---~--~~ 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: find with HABTM problem
What does the find() code look like? It's possible that the problem is with your unconventional column names. It might work better if you use, eg. 'areainteresse_pessoa' for the join table and 'pessoa_id' for the key. Or it might be something else. On Fri, Sep 25, 2009 at 11:30 AM, Wladiston Paiva desenvolvedo...@gmail.com wrote: hi peoples, i have two models is cakephp: class Pessoa extends AppModel { var $name = 'Pessoa'; var $primaryKey = 'codigo'; var $hasAndBelongsToMany = array( 'Areainteresse' = array( 'className' = 'Areainteresse', 'joinTable' = 'areainteressepessoa', 'foreignKey' = 'codigopessoa', 'associationForeignKey' = 'codigoareainteresse' ) ); } and class Areainteresse extends AppModel { var $name = 'Areainteresse'; var $useTable = 'areainteresse'; var $primaryKey = 'codigo'; } when i run the $this-Pessoa-find(). he return me: array(2) { [0]= array(12) { [codigo]= int(6) } [Areainteresse]= array(0) { } } the Pessoa entity is returned normally, however the entity Areainteresse not returned. This only for the find(). the save() work normally. The data are in the table correctly. Anyone have any solution? --- Wladiston Maurício de Paiva http://wladistonpaiva.com.br desenvolvedo...@gmail.com e...@wladistonpaiva.com.br +55 (31) 8435 - 5380 --~--~-~--~~~---~--~~ 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: find with HABTM problem
unfortunately not always possible. because the database already exists. I am only deploying the system in PHP (currently Delphi). and the base is in Firebird. I had problems with the Auth component because of the Firebird, I believe the problem is the integration of the cake with the firebird. I am installing ZendServer with ZendStudio to test via debugger with MySQL to work the problem really is the cake. --- Wladiston Maurício de Paiva http://wladistonpaiva.com.br desenvolvedo...@gmail.com e...@wladistonpaiva.com.br +55 (31) 8435 - 5380 2009/9/25 brian bally.z...@gmail.com What does the find() code look like? It's possible that the problem is with your unconventional column names. It might work better if you use, eg. 'areainteresse_pessoa' for the join table and 'pessoa_id' for the key. Or it might be something else. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Containable, bindModel and HABTM problem
Hello, I have a problem with a couple of models that share a HABTM relationship. I've tried two different approaches, but none provide the desired result. Here are they both, I hope you can help me to fix either of them to get the array I need. I'm using the good old Post hasAndBelongsToMany Tag So, let's say I have three posts: Post #1 has Tags 'cool' and 'cakephp' Post #2 has Tag 'cakephp' Post #3 has Tag 'cool' 'dessert' This is the complicated part. What I want to achieve is to get a resultset (array) that has ONLY the posts which DO NOT JUST contain the Tag 'cakephp', and list their tags. i.e., something that looks like this Array ( [0] = Array ( [Post] = Array ( [id] = 1 [title] = Post1 ) [Tag] = Array ( [0] = Array ( [id] = 1 [name] = cool ) ) ) [1] = Array ( [Post] = Array ( [id] = 3 [title] = Post3 ) [Tag] = Array ( [0] = Array ( [id] = 1 [name] = cool ) [1] = Array ( [id] = 3 [name] = dessert ) ) ) My first approach was to use the Containable behavior. It helps me limit the Tags, but it doesnt let me filter the Posts. $this-Post-find('all', array('contain' = array( 'Tag' = array( 'conditions' = array('not'= array('Tag.name' = 'cakephp') ; This approach will return Posts 1, 2 and 3. but it will show a blank [Tag] array for Post #2 which is no good for me, since I don't want the Post to show up at all. The second approach was to use join tables (inner joins), using unbind and bindModel, as detailed by teknoid in his blog (http:// teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/) $this-Post-unbindModel(array('hasAndBelongsToMany'=array('Tag'))); $this-Post-bindModel(array('hasOne'=array( 'PostsTag'=array( 'foreignKey'=false, 'type'='INNER', 'conditions'=array('PostsTag.Post_id = Post.id') ), 'Tag'=array( 'className' = 'Tag', 'foreignKey'=false, 'type'='INNER', 'conditions'=array( 'Tag.id = PostsTag.Tag_id' ); $this-Post-find('all', array(' 'not' = array('Tag.name' = 'cakephp' ; This case almost provides me with the array I want (or at least one that I can use), except for the part that Post #3 will appear twice. One with the 'cool' tag as the result and one with the 'dessert' tag as the result. Also, in this case, the Tags do not nest inside of the [Tag] section of the array, which is desirable. So, my question is: is there a way to tweak any of these two methods to get the result I want?? I tried to provide as many details as I could. If i didn't make myself clear, please let me know. Thanks in advance, Ponch316 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
HABTM problem
I have standard users table. Every user can have many accounts (account is a group of permissions, like a role) and every account can be linked to many users. Relation is HABTM as you can see. When I call: $accounts=$this-User-find('first', array('conditions' = array ('User.user_id' = 1))); i get: Array ( [User] = Array ( [user_id] = 1 [contact_name] = Administrator [email_address] = t...@test.pl [username] = root [password] = 7a89a595cfcjeb85480202a143e37d2e [language] = pl [default_account_id] = 2 [comments] = [active] = 1 [sso_user_id] = [date_created] = 2009-08-13 18:45:50 [date_last_login] = 2009-08-17 14:33:27 [email_updated] = 2009-08-13 18:45:50 ) [Account] = Array ( ) ) Account array is empty. SQL generated by cake doesn't even mention accounts or account_user_assoc table: SELECT `User`.`user_id`, `User`.`contact_name`, `User`.`email_address`, `User`.`username`, `User`.`password`, `User`.`language`, `User`.`default_account_id`, `User`.`comments`, `User`.`active`, `User`.`sso_user_id`, `User`.`date_created`, `User`.`date_last_login`, `User`.`email_updated` FROM `ox2_users` AS `User` WHERE `User`.`user_id` = 1 LIMIT 1 Can anyone help me with this? My User model code: class User extends AppModel { var $name = 'User'; var $recursive=1; var $hasAndBelongsToMany = array( 'Account' = array( 'className' = 'Account', 'joinTable' = 'account_user_assoc', 'foreignKey' = 'user_id', 'associationForeignKey' = 'account_id', 'unique' = true ) ); function hashPasswords($data){ $data['User']['password']=md5($data['User']['password']); return $data; } } Account model code: class Account extends AppModel { var $name = 'Account'; var $primaryKey = 'account_id'; } --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
HABTM - problem when reading data for non-unique keys
Here's my problem: If the foreign key in the HABTM join table isn't unique and could therefore return multiple matching records, all the records should be part of the returned dataset. The way it works now, only the first record is returned and the others are skipped. Simple example: Model pallet HABTM product with join table pallets_products Example pallets_products data: pallet_id, product_id, quantity 1, 1, 10 1, 2, 10 1, 2, 15 Here pallet_id 1 has three lines in the join table although two of the lines are actually the same product_id but with a different quantity. This causes the following problem: $pallet = $this-Pallet-find('all', array('conditions'=array ('Pallet.id'=$id))) The code above produces the following (correct) SQL: SELECT `Product`.`id`, `Product`.`description`, `PalletsProduct`.`id`, `PalletsProduct`.`pallet_id`, `PalletsProduct`.`product_id`, `PalletsProduct`.`quantity` FROM `products` AS `Product` JOIN `pallets_products` AS `PalletsProduct` ON (`PalletsProduct`.`pallet_id` = 1 AND `PalletsProduct`.`product_id` = `Product`.`id`) WHERE 1 = 1 The above SQL statement correctly returns THREE lines - one for every matched line in the join table. However, the $pallet array produced only contains TWO matched lines from the join table. It skips the subsequent line which has product_id of 2. What gives here? Some say I have bad DB design (I don't believe so), others say this is how it should be (I also don't believe so). Interestingly the same issue has been raised as a ticket some 10 months ago but from reading the ticket I feel that the cake team didn't bother to understand what it meant and preferred just to close it (https://trac.cakephp.org/ticket/5128). I even discussed this briefly with mark story but he didn't seem interested in actually understanding the problem preferring instead to just tell me that I was doing something wrong. Ho hum. --~--~-~--~~~---~--~~ 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: HABTM problem
it is clear now thanks for your help :-) -- View this message in context: http://n2.nabble.com/HABTM-problem-tp2363919p2367984.html Sent from the CakePHP mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
HABTM problem
halo, i have a question about the HABTM relationship let me use the most common example on web there are 3 table database: 1. posts (post_id, name) 2. posts_tags (post_id, tag_id) 3. tags (tag_id, name) and let's take a look on the tags table tag_id name --- 1 David 2 Terry 3 Ronaldo and then i created a view for edit.ctp the Post. in the post controller $ names = $this-Post-Tag-find('list',array('fields'=array('tag_id', 'name))); $this-set(compact('names')); In the view, I created a form to update the posts tr td valign=topWho is tagged (Name)/td td?php echo $form-input('Tag.Name' ,array('label'=false)); ?/td /tr now i can update the Post and select who was tagged in it without any problem. here my question comes: as more ppl are added in the tags table i added another column tag_id namefamilyname -- 1 DavidBeckham 2 John Terry 3 Christano Ronaldo 4 DavidTerry Since the controller create a key value pair (tag_id and name only), so now there are 4 options which are David, John, Christano and David. There are 2 David now! I would like to add another input for family name in the view. Sth like tr td valign=topWho are tagged (Name)/td td?php echo $form-input('Tag.Name' ,array('label'=false)); ?/td /tr tr td valign=topWho are tagged (Family Name)/td td?php echo $form-input('Tag.FamilyName' ,array('label'=false)); ?/td /tr But I dun know how to make it works? I know I can combine the name and family name such that one tag_id is mapped to one name to solve this problem. But I just wanna know whether it is possible for one key to be mapped with more than one values. Thanks very much for your help.:-) kit -- View this message in context: http://n2.nabble.com/HABTM-problem-tp2363919p2363919.html Sent from the CakePHP mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ 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: HABTM problem
here my question comes: as more ppl are added in the tags table i added another column tag_id namefamilyname -- 1 DavidBeckham 2 John Terry 3 Christano Ronaldo 4 DavidTerry Since the controller create a key value pair (tag_id and name only), so now there are 4 options which are David, John, Christano and David. There are 2 David now! I would like to add another input for family name in the view. Sth like tr td valign=topWho are tagged (Name)/td td?php echo $form-input('Tag.Name' ,array('label'=false)); ?/td /tr tr td valign=topWho are tagged (Family Name)/td td?php echo $form-input('Tag.FamilyName' ,array('label'=false)); ?/td /tr But I dun know how to make it works? I know I can combine the name and family name such that one tag_id is mapped to one name to solve this problem. But I just wanna know whether it is possible for one key to be mapped with more than one values. Absolutely not. The entire purpose of an array key is to unambiguously point to a single value. Just as Tags must be unique. If they are not there's no point in using them as they'll be useless. If you want to update your tags to incorporate the family name, append it to the value of name. --~--~-~--~~~---~--~~ 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: Strange habtm problem - saving in other tables
If I comment out other habtm relationships, leaving only var $hasAndBelongsToMany = array( 'HasAsFriend' = array( 'className' = 'User', 'joinTable' = 'friends', 'foreignKey' = 'user_id', 'associationForeignKey' = 'friend_id', 'uniq' = false, 'conditions' = '', ), ); in my User model, then the save() will go flawlessly. However, if I leave those relationships in User model, then the data is inserted into other tables even if I manually unbindModel() them before calling $this-User-save(). I'm confused. Is there anyone who knows why this is happening? Or maybe I should just use a $this-User-query() to do the saving job and insert the data in the right table? :( On 5月8日, 上午6時13分, largon [EMAIL PROTECTED] wrote: Hi, I'm on a project that users can add other users as friends, families, or block them. So I've set up some habtm behaviors for that. The tables (friends, families, blocks) look very similar, all with (user_id, friend_id) or (user_id, family_id) as keys. But when I save a data, like calling: $this-data['User']['id'] = 1; $this-data['HasAsFriend']['HasAsFriend'] = 2; $this-User-save($this-data); I'll have not only user1 adding user2 as friend, but also user2 adding user1 as friend. What's more, they're each other's families and user1 is blocking user2 too. (The data got inserted into families table and blocks table too.) I posted my user model relationships athttp://bin.cakephp.org/view/241705085 I also tried the behavior athttp://bakery.cakephp.org/articles/view/add-delete-habtm-behavior , but with the code: $this-User-habtmAdd('HasAsFriend', 1, 2); Also results the same as inserting into families table and blocks table. I'm troubled, I'm not sure why this is happening. Any clues is greatly appreciated. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Strange habtm problem - saving in other tables
I added some logging just to make sure the relationships are unbound: $this-User-unbindAll(array('hasAndBelongsToMany' = array('HasAsFriend'))); $this-log(current habtm: . print_r($this-User- hasAndBelongsToMany, true)); The error log reads: 2008-05-08 17:03:49 Error: current habtm: Array ( [HasAsFriend] = Array ( [className] = User [joinTable] = friends [foreignKey] = user_id [associationForeignKey] = friend_id [uniq] = [conditions] = [with] = Friend [fields] = [order] = [limit] = [offset] = [unique] = 1 [finderQuery] = [deleteQuery] = [insertQuery] = ) ) Which indicates that those relationships are unbound successfully. But the habtmAdd still inserts into other tables: $this-User-habtmAdd('HasAsFriend', 1, 3); will result with SQL queries: 28 INSERT INTO `friends` (`user_id`,`friend_id`) VALUES (1,3) 29 SELECT `Friend`.`id` FROM `friends` AS `Friend` WHERE `friend_id` = 1 30 INSERT INTO `friends` (`friend_id`,`user_id`) VALUES (1,3) 31 SELECT `Family`.`id` FROM `families` AS `Family` WHERE `user_id` = 1 32 INSERT INTO `families` (`user_id`,`family_id`) VALUES (1,3) 33 SELECT `Family`.`id` FROM `families` AS `Family` WHERE `family_id` = 1 34 INSERT INTO `families` (`family_id`,`user_id`) VALUES (1,3) 35 SELECT `Block`.`id` FROM `blocks` AS `Block` WHERE `user_id` = 1 36 INSERT INTO `blocks` (`user_id`,`block_id`) VALUES (1,3) This is wierd. Is this a bug in cake or is it my misconfiguration in User model? On 5月8日, 下午4時41分, largon [EMAIL PROTECTED] wrote: If I comment out other habtm relationships, leaving only var $hasAndBelongsToMany = array( 'HasAsFriend' = array( 'className' = 'User', 'joinTable' = 'friends', 'foreignKey' = 'user_id', 'associationForeignKey' = 'friend_id', 'uniq' = false, 'conditions' = '', ), ); in my User model, then the save() will go flawlessly. However, if I leave those relationships in User model, then the data is inserted into other tables even if I manually unbindModel() them before calling $this-User-save(). I'm confused. Is there anyone who knows why this is happening? Or maybe I should just use a $this-User-query() to do the saving job and insert the data in the right table? :( On 5月8日, 上午6時13分, largon [EMAIL PROTECTED] wrote: Hi, I'm on a project that users can add other users as friends, families, or block them. So I've set up some habtm behaviors for that. The tables (friends, families, blocks) look very similar, all with (user_id, friend_id) or (user_id, family_id) as keys. But when I save a data, like calling: $this-data['User']['id'] = 1; $this-data['HasAsFriend']['HasAsFriend'] = 2; $this-User-save($this-data); I'll have not only user1 adding user2 as friend, but also user2 adding user1 as friend. What's more, they're each other's families and user1 is blocking user2 too. (The data got inserted into families table and blocks table too.) I posted my user model relationships athttp://bin.cakephp.org/view/241705085 I also tried the behavior athttp://bakery.cakephp.org/articles/view/add-delete-habtm-behavior , but with the code: $this-User-habtmAdd('HasAsFriend', 1, 2); Also results the same as inserting into families table and blocks table. I'm troubled, I'm not sure why this is happening. Any clues is greatly appreciated. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Strange habtm problem - saving in other tables
For anybody who's following this thread, or had the same problem, or dived in during a google: This seems like a bug mentioned at https://trac.cakephp.org/ticket/4558 After adding a unset($newValues) as the ticket mentions the problem goes away. Thanks all! On May 8, 5:08 pm, largon [EMAIL PROTECTED] wrote: I added some logging just to make sure the relationships are unbound: $this-User-unbindAll(array('hasAndBelongsToMany' = array('HasAsFriend'))); $this-log(current habtm: . print_r($this-User- hasAndBelongsToMany, true)); The error log reads: 2008-05-08 17:03:49 Error: current habtm: Array ( [HasAsFriend] = Array ( [className] = User [joinTable] = friends [foreignKey] = user_id [associationForeignKey] = friend_id [uniq] = [conditions] = [with] = Friend [fields] = [order] = [limit] = [offset] = [unique] = 1 [finderQuery] = [deleteQuery] = [insertQuery] = ) ) Which indicates that those relationships are unbound successfully. But the habtmAdd still inserts into other tables: $this-User-habtmAdd('HasAsFriend', 1, 3); will result with SQL queries: 28 INSERT INTO `friends` (`user_id`,`friend_id`) VALUES (1,3) 29 SELECT `Friend`.`id` FROM `friends` AS `Friend` WHERE `friend_id` = 1 30 INSERT INTO `friends` (`friend_id`,`user_id`) VALUES (1,3) 31 SELECT `Family`.`id` FROM `families` AS `Family` WHERE `user_id` = 1 32 INSERT INTO `families` (`user_id`,`family_id`) VALUES (1,3) 33 SELECT `Family`.`id` FROM `families` AS `Family` WHERE `family_id` = 1 34 INSERT INTO `families` (`family_id`,`user_id`) VALUES (1,3) 35 SELECT `Block`.`id` FROM `blocks` AS `Block` WHERE `user_id` = 1 36 INSERT INTO `blocks` (`user_id`,`block_id`) VALUES (1,3) This is wierd. Is this a bug in cake or is it my misconfiguration in User model? On 5月8日, 下午4時41分, largon [EMAIL PROTECTED] wrote: If I comment out other habtm relationships, leaving only var $hasAndBelongsToMany = array( 'HasAsFriend' = array( 'className' = 'User', 'joinTable' = 'friends', 'foreignKey' = 'user_id', 'associationForeignKey' = 'friend_id', 'uniq' = false, 'conditions' = '', ), ); in my User model, then the save() will go flawlessly. However, if I leave those relationships in User model, then the data is inserted into other tables even if I manually unbindModel() them before calling $this-User-save(). I'm confused. Is there anyone who knows why this is happening? Or maybe I should just use a $this-User-query() to do the saving job and insert the data in the right table? :( On 5月8日, 上午6時13分, largon [EMAIL PROTECTED] wrote: Hi, I'm on a project that users can add other users as friends, families, or block them. So I've set up some habtm behaviors for that. The tables (friends, families, blocks) look very similar, all with (user_id, friend_id) or (user_id, family_id) as keys. But when I save a data, like calling: $this-data['User']['id'] = 1; $this-data['HasAsFriend']['HasAsFriend'] = 2; $this-User-save($this-data); I'll have not only user1 adding user2 as friend, but also user2 adding user1 as friend. What's more, they're each other's families and user1 is blocking user2 too. (The data got inserted into families table and blocks table too.) I posted my user model relationships athttp://bin.cakephp.org/view/241705085 I also tried the behavior athttp://bakery.cakephp.org/articles/view/add-delete-habtm-behavior , but with the code: $this-User-habtmAdd('HasAsFriend', 1, 2); Also results the same as inserting into families table and blocks table. I'm troubled, I'm not sure why this is happening. Any clues is greatly appreciated. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Strange habtm problem - saving in other tables
Hi, I'm on a project that users can add other users as friends, families, or block them. So I've set up some habtm behaviors for that. The tables (friends, families, blocks) look very similar, all with (user_id, friend_id) or (user_id, family_id) as keys. But when I save a data, like calling: $this-data['User']['id'] = 1; $this-data['HasAsFriend']['HasAsFriend'] = 2; $this-User-save($this-data); I'll have not only user1 adding user2 as friend, but also user2 adding user1 as friend. What's more, they're each other's families and user1 is blocking user2 too. (The data got inserted into families table and blocks table too.) I posted my user model relationships at http://bin.cakephp.org/view/241705085 I also tried the behavior at http://bakery.cakephp.org/articles/view/add-delete-habtm-behavior , but with the code: $this-User-habtmAdd('HasAsFriend', 1, 2); Also results the same as inserting into families table and blocks table. I'm troubled, I'm not sure why this is happening. Any clues is greatly appreciated. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Yet another HABTM problem with self-referencing model (var useTable)
I was just having the same problem, used your method and it's working fine now. On Mar 30, 9:36 pm, ste.ve [EMAIL PROTECTED] wrote: To visualize it better, these are my example Model definitions WORKS: class Tag extends AppModel { var $hasAndBelongsToMany = array( 'Tag2' = array( 'foreignKey' = 'tag_id', 'associationForeignKey' = 'tag2_id', ) ); } class Tag2 extends AppModel { var $useTable = tags; var $hasAndBelongsToMany = array( 'Tag' = array( 'foreignKey' = 'tag2_id', 'associationForeignKey' = 'tag_id', )); } DOESN'T WORK (in the result set, all rows for Tag2 contain the value from Tag - the number of results is correct, anyhow) class Tag extends AppModel { var $hasAndBelongsToMany = array('Tag2' ); } class Tag2 extends AppModel { var $useTable = tags; var $hasAndBelongsToMany = array( 'Tag' ); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Yet another HABTM problem with self-referencing model (var useTable)
You just need to change the alias : class Tag extends AppModel { var $hasAndBelongsToMany = array( 'RelatedTag' = array('className' = 'Tag') ); } In your resultset the `Tag` key will now refer to the main tag and the `RelatedTag` will contain the related tags. Of course you can change the alias to anything suitable. On Apr 4, 11:17 am, dizz [EMAIL PROTECTED] wrote: I was just having the same problem, used your method and it's working fine now. On Mar 30, 9:36 pm, ste.ve [EMAIL PROTECTED] wrote: To visualize it better, these are my example Model definitions WORKS: class Tag extends AppModel { var $hasAndBelongsToMany = array( 'Tag2' = array( 'foreignKey' = 'tag_id', 'associationForeignKey' = 'tag2_id', ) ); } class Tag2 extends AppModel { var $useTable = tags; var $hasAndBelongsToMany = array( 'Tag' = array( 'foreignKey' = 'tag2_id', 'associationForeignKey' = 'tag_id', )); } DOESN'T WORK (in the result set, all rows for Tag2 contain the value from Tag - the number of results is correct, anyhow) class Tag extends AppModel { var $hasAndBelongsToMany = array('Tag2' ); } class Tag2 extends AppModel { var $useTable = tags; var $hasAndBelongsToMany = array( 'Tag' ); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Yet another HABTM problem with self-referencing model (var useTable)
I have a Model (Model_1) which is related to itself by a second model (Model_2) by a HABTM relation. Model_2 uses a custom table (var $usetable = model_1) The problem: When I make a find call on Model_1, it returns correctly the row for itself, and the correct number of rows for Model_2, BUT all the rows of Model_2 contain the information of Model_1! For example, I have the model tag related with habtm to tag2 (tag2 has useTable tag). When I query tag for a specific entry, I get tag and the correct number of tag2, but every tag2 contains the data of the one tag row. There is a workaround: when I define the foreignKey and associationForeignKey and exchange their values, it works! Like (for Model_1): 'foreignKey' = 'model_1_id','associationForeignKey' = 'model_2_id'. If I don't define it, or if I defined it the correct way ( 'foreignKey' = 'model_2_id','associationForeignKey' = 'model_1_id') I get the problem described above. The SQL generated, however is correct and the same in both szenarios (and it returns correct results when I try it manually in PhpMyAdmin). It seems that Cake internally gets the results wrong inside its model functions. Is anyone able to reproduce this? Thanks, Stefan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Yet another HABTM problem with self-referencing model (var useTable)
To visualize it better, these are my example Model definitions WORKS: class Tag extends AppModel { var $hasAndBelongsToMany = array( 'Tag2' = array( 'foreignKey' = 'tag_id', 'associationForeignKey' = 'tag2_id', ) ); } class Tag2 extends AppModel { var $useTable = tags; var $hasAndBelongsToMany = array( 'Tag' = array( 'foreignKey' = 'tag2_id', 'associationForeignKey' = 'tag_id', )); } DOESN'T WORK (in the result set, all rows for Tag2 contain the value from Tag - the number of results is correct, anyhow) class Tag extends AppModel { var $hasAndBelongsToMany = array('Tag2' ); } class Tag2 extends AppModel { var $useTable = tags; var $hasAndBelongsToMany = array( 'Tag' ); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM problem - Underscore in primary key name?
Nvm, fixed. Was searching the google groups for the wrong term. On Nov 21, 12:55 pm, Action [EMAIL PROTECTED] wrote: I need to set up a HABTM association between two tables: users and teams. The problem I'm having is that the primary key in the users table is called user_id, not id. (I am not allowed to change this). How do I set up my join table and association so it associates Team.id with User.user_id, not User.id? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
HABTM problem - Underscore in primary key name?
I need to set up a HABTM association between two tables: users and teams. The problem I'm having is that the primary key in the users table is called user_id, not id. (I am not allowed to change this). How do I set up my join table and association so it associates Team.id with User.user_id, not User.id? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM problem - Underscore in primary key name?
if you did check the manual, in 'models' chapter, you find about model variables: http://manual.cakephp.org/chapter/models $primaryKey If this model relates to a database table, and the table's primary key is not named 'id', use this variable to tell Cake the name of the primary key. Spark On Nov 21, 2007 3:55 PM, Action [EMAIL PROTECTED] wrote: I need to set up a HABTM association between two tables: users and teams. The problem I'm having is that the primary key in the users table is called user_id, not id. (I am not allowed to change this). How do I set up my join table and association so it associates Team.id with User.user_id, not User.id? Thanks. -- [livesets] http://djspark.com.br/ [web] http://sydi.net [filmes] http://melhoresfilmes.com.br --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: habtm problem
On Nov 20, 7:24 am, Dianne van Dulken [EMAIL PROTECTED] wrote: Thanks for that Yolabingo. It turned out I was making it all a bit too difficult for myself, so I'll put the solution here in case anyone else is having the same problem. Same as above except what I had to do before save is to force the ['articles']['articles'] values to be my array. So function beforeSave() { $this-data['Articles']['Articles'] = explode(,, $_POST[data] ['teasers'][articles]); // saves the articles list information in the joint table. return parent::beforeSave(); } is the correct beforeSave. Why are you referring to $_POST at all? Models should never look for info like that, it'll already be in $this- data when you are in the model, and if it isn't there is an error/ misunderstanding in your controller code. AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: habtm problem
Thanks for that Yolabingo. It turned out I was making it all a bit too difficult for myself, so I'll put the solution here in case anyone else is having the same problem. Same as above except what I had to do before save is to force the ['articles']['articles'] values to be my array. So function beforeSave() { $this-data['Articles']['Articles'] = explode(,, $_POST[data] ['teasers'][articles]); // saves the articles list information in the joint table. return parent::beforeSave(); } is the correct beforeSave. Don't you hate it when you've wasted time making something that should be simple complicated :S --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: habtm problem
On Nov 12, 5:35 pm, Dianne van Dulken [EMAIL PROTECTED] wrote: function beforeSave() { $articles = explode(,, $_POST[data]['Teaser'][articles]); $this-Teaser-habtmAdd('Article', $this-data['Teaser']['id'], $articles); return parent::beforeSave(); //return false; } At first glance things appear to be kosher, except that you probably don't want to call habtmAdd() from beforeSave(). beforeSave() should be used to format and validate data only, not attempt to save anything (hence the 'before' in the name). The code in your beforeSave() function is executed anytime you make a call to save(), which is what habtmAdd() does. I believe you'd have an infinite recursion if it weren't breaking at some point. Short answer, call habtmAdd() from within another function. HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
HABTM problem similar to described in manual's model's last section
hi, its ahsan. I am new to cakephp , but old to php :-) In the last section of the manual 's model description .. its described about the details of HABTM association between posts and tags.. the scenario presented there in last example is to associate a newly created post with a relevant tags, while we are adding a new post. I am exactly in the same situation .. I have HABTM association between two models dealer : product when creating a dealer, i want to be able to associate one or many products to the dealer. In manual ,they have used $html-selectTag('Tag/Tag',$tags,null. etc) How will this work in my case.. because , i have tried to replace 'Tag/Tag' with 'Product/Product' and $tags with $products.. but of now use.. Its gives the error Notice: Undefined variable: products in D:\Development Work Area\Installations\wamp\www\cake\app\views\dealers\add.thtml on line 31 Pleasse help me Regards --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: HABTM problem similar to described in manual's model's last section
Generally if you're getting undefined variable it's because you haven't set the variable for the view to access. It depends what's on line 31 in your add.thtml file, but I'm guessing it's: $html-selectTag('Product/Product',$products) In which case you just need to set the $products variable in your controller for the view to access: $this-set('products',$products); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---