Re: hasMany / belongsTo not working
On Tue, Jul 30, 2013 at 6:50 AM, WhyNotSmile wrote: > I have a pretty simple pair of objects, Photo and Album, defined as follows: >> >> class Album extends Model { >> public $name = 'Album'; >> >> public $hasMany = array( >> 'Photo' => array( >> 'className' => 'Photo', >> 'order' => 'Photo.order ASC' >> ) >> ); >> } > >> class Photo extends Model { >> public $name = 'Photo'; >> public $belongsTo = array('Album'); >> } > > > I currently have 3 albums, one with 0 photos, one with 1 photo, and one with > 2 photos. When I do the following in the controller, I expect to get 3 > albums back: > >> $albumlist = $this->Album->find('all'); >> debug($albumlist); > > But in fact, I get 4 - the one with 2 photos is shown twice. If I had > another photo, I get the album back 3 times. I'm absolutely stumped as to > what's causing this, and have a feeling it must be something really stupid > that I've done. I've set up much more complex models than this in the past, > with no problems. Did you inserted the records using those CakePHP models? Is your database modeled properly? How the related SQL queries looks like in debug mode? Check if you get the same information querying the database directly with something like this (assuming the standard conventions) in your SGBD query prompt. SELECT p.* FROM photos p INNER JOIN albums a ON (p.album_id=a.id) Assuming you followed the standard conventions and just for a debugging purpose, try to simplify your associations and redo the tests. // Album public $hasMany = 'Photo'; // Photo public $belongsTo = 'Album'; Hope it helps. MARCELO DE FREITAS ANDRADE https://mailstrom.co/mfandrade -- 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.
hasMany / belongsTo not working
I have a pretty simple pair of objects, Photo and Album, defined as follows: > class Album extends Model { > public $name = 'Album'; > > public $hasMany = array( > 'Photo' => array( > 'className' => 'Photo', > 'order' => 'Photo.order ASC' > ) > ); > } > class Photo extends Model { > public $name = 'Photo'; > public $belongsTo = array('Album'); > } I currently have 3 albums, one with 0 photos, one with 1 photo, and one with 2 photos. When I do the following in the controller, I expect to get 3 albums back: $albumlist = $this->Album->find('all'); > debug($albumlist); But in fact, I get 4 - the one with 2 photos is shown twice. If I had another photo, I get the album back 3 times. I'm absolutely stumped as to what's causing this, and have a feeling it must be something really stupid that I've done. I've set up much more complex models than this in the past, with no problems. Also, when I try to retrieve a photo, I don't get the associated album back, just the photo itself. Can anyone see anything wrong in what I've got so far? 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 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: DropDown list fields for HasMany-BelongsTo association
Hi Ahmed, Its simple, you may edit the User model, where its return the drop down values array, you can change the field name as you want. If feels difficulty then share you code. Cheers!.. Saran On Tue, Apr 23, 2013 at 12:06 PM, Ahmed Abdelsalam wrote: > Hi, > > I'm new to cakephp, and I created an association between two tables Users > and Notes. User has many notes and Note belongs to user > > When I used bake to generate code. The add action of Note, a drop down > list of users should appear in the form. However, the generated drop down > list shows the primary ID of users. I want to use dropdown list of > usernames or any other field. > > Any help? > > Ahmed > > -- > 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. > > > -- 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.
DropDown list fields for HasMany-BelongsTo association
Hi, I'm new to cakephp, and I created an association between two tables Users and Notes. User has many notes and Note belongs to user When I used bake to generate code. The add action of Note, a drop down list of users should appear in the form. However, the generated drop down list shows the primary ID of users. I want to use dropdown list of usernames or any other field. Any help? Ahmed -- 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: Inefficient SQL queries with hasMany/belongsTo relationship
the question why do you want to paginate comments while you are paginating posts? in general when you paginate the main model (Post), you just include summary fields from the associated models example -last commented by commenter name -last comment title... not body... (text) -last commented in (date) -total number of comments (number) -total number of visits (number) etc... so either these fields are redundant in the posts table just for performance issue (many question marks here maybe) or you do custom pagination queries to retrieve the last things for each post (in the current pagination of course... the current page I mean) --~--~-~--~~~---~--~~ 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: Inefficient SQL queries with hasMany/belongsTo relationship
On Oct 23, 7:43 pm, Miles J wrote: > Im curious as how you think a join would be better? You are you going > to grab multiple comment rows for a single post, while paginating > posts? 2 queries is faster then sub-queries. > > More queries is sometimes better than complex queries. Well, you may certainly be right, I never professed to be an SQL pro. Can you explain why two queries would be better in this case? I know this is not the best measurement, but looking at the query times Cake outputs in dev mode, they actually seem to be almost equal. Should I just stop worrying and love ActiveCake? On the other hand, two queries may be faster for MySQL, but the extra query will still add *some* network latency. --~--~-~--~~~---~--~~ 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: Inefficient SQL queries with hasMany/belongsTo relationship
Im curious as how you think a join would be better? You are you going to grab multiple comment rows for a single post, while paginating posts? 2 queries is faster then sub-queries. More queries is sometimes better than complex queries. --~--~-~--~~~---~--~~ 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: Inefficient SQL queries with hasMany/belongsTo relationship
You might want to look into : http://book.cakephp.org/view/816/counterCache-Cache-your-count Andras On Oct 23, 2009, at 7:30 PM, bonecandy wrote: > >> How slow. Feel free to propose an alternative that achieves the same >> thing. > > Okay, well, I researched IN again and it appears that IN is really > only slow in sub-selects where a join would be much faster. Sorry, I > posted without double-checking, I conflated sub-selects with any > select ;( > >> So don't ask for it :) > > That's the problem isn't it - figuring out the best way not to ask for > it :P > > >> Post hasOne Comment would generate that - but good luck paginating >> it. >> As soon as any post has more than 1 comment your post index is going >> to have duplicates or holes (depending on if/how you try to 'fix' >> that). But why are you requesting comments at all? > > Well, I'd like to list the amount of comments each post has on the > main page. There might be another way to get this, but it still irks > me that Cake produces two queries when one query would suffice. I > thought using a join in this case would be the obvious choice for > Cake's ORM (does it have an official name? ActiveCake?). > I thought about overriding the paginate method in my Post model, but > the extra query only adds about 1-5ms of time and the records are > limited to 20 so IN wouldn't be terribly slow, so I'll probably ignore > this issue for now. In the future I'll probably just implement my own > pagination separate from Cake itself. > >> Probably because he doesn't know about recursion (yet)? >> A find('all') command will do exaclty that, find all... So if you >> do a >> find('all') of the posts, itll also get all the commens, tags, users, >> whatever the post has relationships with... If in a certain action >> you >> just need the posts, add $this->Product->recursive = 0; before the >> call. It'll limit the search to only posts. (recursive is kinda >> like a >> depth-level of search) > > I'm not sure if reducing recursion would help me here. I actually > *want* those comments - or at least their count for each post. > > --~--~-~--~~~---~--~~ 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: Inefficient SQL queries with hasMany/belongsTo relationship
> How slow. Feel free to propose an alternative that achieves the same > thing. Okay, well, I researched IN again and it appears that IN is really only slow in sub-selects where a join would be much faster. Sorry, I posted without double-checking, I conflated sub-selects with any select ;( > So don't ask for it :) That's the problem isn't it - figuring out the best way not to ask for it :P > Post hasOne Comment would generate that - but good luck paginating it. > As soon as any post has more than 1 comment your post index is going > to have duplicates or holes (depending on if/how you try to 'fix' > that). But why are you requesting comments at all? Well, I'd like to list the amount of comments each post has on the main page. There might be another way to get this, but it still irks me that Cake produces two queries when one query would suffice. I thought using a join in this case would be the obvious choice for Cake's ORM (does it have an official name? ActiveCake?). I thought about overriding the paginate method in my Post model, but the extra query only adds about 1-5ms of time and the records are limited to 20 so IN wouldn't be terribly slow, so I'll probably ignore this issue for now. In the future I'll probably just implement my own pagination separate from Cake itself. >Probably because he doesn't know about recursion (yet)? >A find('all') command will do exaclty that, find all... So if you do a >find('all') of the posts, itll also get all the commens, tags, users, >whatever the post has relationships with... If in a certain action you >just need the posts, add $this->Product->recursive = 0; before the >call. It'll limit the search to only posts. (recursive is kinda like a >depth-level of search) I'm not sure if reducing recursion would help me here. I actually *want* those comments - or at least their count for each post. --~--~-~--~~~---~--~~ 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: Inefficient SQL queries with hasMany/belongsTo relationship
Probably because he doesn't know about recursion (yet)? A find('all') command will do exaclty that, find all... So if you do a find('all') of the posts, itll also get all the commens, tags, users, whatever the post has relationships with... If in a certain action you just need the posts, add $this->Product->recursive = 0; before the call. It'll limit the search to only posts. (recursive is kinda like a depth-level of search) On 23 okt, 09:05, AD7six wrote: > On 23 oct, 05:32, bonecandy wrote: > > > > > Hi, this is my first post here - I'm new to CakePHP, but not to > > programming or PHP. > > Anyway, to get acquainted with Cake I've been making a blog (I know, > > crazy, huh?). So, I have my posts table and model, which has a hasMany > > relationship with comments, and my comments table and model, which has > > a belongsTo relationship with my post model. > > This works just fine - I'm using the paginate helper like so: > > > $this->set('posts',$this->paginate('Post')); > > > And I can access the comments just fine. However, the problem is the > > query is so inefficient! > > These are the queries Cake produces that I have issues with: > > > SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`, > > `Post`.`date_created`, `Post`.`date_modified` FROM `posts` AS `Post` > > WHERE 1 = 1 ORDER BY `Post`.`id` desc LIMIT 20 > > > SELECT `Comments`.`id`, `Comments`.`user`, `Comments`.`body`, > > `Comments`.`post_id` FROM `comments` AS `Comments` WHERE > > `Comments`.`post_id` IN (22, 21, 20, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, > > 3, 2, 1) > > > The 'IN' MySQL operator is slow. > > How slow. Feel free to propose an alternative that achieves the same > thing. > > > More importantly, that extra query > > is unnecessary! > > So don't ask for it :) > > > Is it possible to get CakePHP to combine the two and > > produce something like this? > > > SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`, > > `Post`.`date_created`, `Post`.`date_modified`,`Comments`.* FROM > > `posts` AS `Post` LEFT JOIN `comments` AS `Comments` ON > > `Comments`.`post_id` = `Post`.`id` ORDER BY `Post`.`id` desc LIMIT 20 > > > I've searched this group as well as Google and haven't really found > > much of anything about this. > > Post hasOne Comment would generate that - but good luck paginating it. > As soon as any post has more than 1 comment your post index is going > to have duplicates or holes (depending on if/how you try to 'fix' > that). But why are you requesting comments at all? > > AD --~--~-~--~~~---~--~~ 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: Inefficient SQL queries with hasMany/belongsTo relationship
On 23 oct, 05:32, bonecandy wrote: > Hi, this is my first post here - I'm new to CakePHP, but not to > programming or PHP. > Anyway, to get acquainted with Cake I've been making a blog (I know, > crazy, huh?). So, I have my posts table and model, which has a hasMany > relationship with comments, and my comments table and model, which has > a belongsTo relationship with my post model. > This works just fine - I'm using the paginate helper like so: > > $this->set('posts',$this->paginate('Post')); > > And I can access the comments just fine. However, the problem is the > query is so inefficient! > These are the queries Cake produces that I have issues with: > > SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`, > `Post`.`date_created`, `Post`.`date_modified` FROM `posts` AS `Post` > WHERE 1 = 1 ORDER BY `Post`.`id` desc LIMIT 20 > > SELECT `Comments`.`id`, `Comments`.`user`, `Comments`.`body`, > `Comments`.`post_id` FROM `comments` AS `Comments` WHERE > `Comments`.`post_id` IN (22, 21, 20, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, > 3, 2, 1) > > The 'IN' MySQL operator is slow. How slow. Feel free to propose an alternative that achieves the same thing. > More importantly, that extra query > is unnecessary! So don't ask for it :) > Is it possible to get CakePHP to combine the two and > produce something like this? > > SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`, > `Post`.`date_created`, `Post`.`date_modified`,`Comments`.* FROM > `posts` AS `Post` LEFT JOIN `comments` AS `Comments` ON > `Comments`.`post_id` = `Post`.`id` ORDER BY `Post`.`id` desc LIMIT 20 > > I've searched this group as well as Google and haven't really found > much of anything about this. Post hasOne Comment would generate that - but good luck paginating it. As soon as any post has more than 1 comment your post index is going to have duplicates or holes (depending on if/how you try to 'fix' that). But why are you requesting comments at all? AD --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Inefficient SQL queries with hasMany/belongsTo relationship
Hi, this is my first post here - I'm new to CakePHP, but not to programming or PHP. Anyway, to get acquainted with Cake I've been making a blog (I know, crazy, huh?). So, I have my posts table and model, which has a hasMany relationship with comments, and my comments table and model, which has a belongsTo relationship with my post model. This works just fine - I'm using the paginate helper like so: $this->set('posts',$this->paginate('Post')); And I can access the comments just fine. However, the problem is the query is so inefficient! These are the queries Cake produces that I have issues with: SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`, `Post`.`date_created`, `Post`.`date_modified` FROM `posts` AS `Post` WHERE 1 = 1 ORDER BY `Post`.`id` desc LIMIT 20 SELECT `Comments`.`id`, `Comments`.`user`, `Comments`.`body`, `Comments`.`post_id` FROM `comments` AS `Comments` WHERE `Comments`.`post_id` IN (22, 21, 20, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) The 'IN' MySQL operator is slow. More importantly, that extra query is unnecessary! Is it possible to get CakePHP to combine the two and produce something like this? SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`, `Post`.`date_created`, `Post`.`date_modified`,`Comments`.* FROM `posts` AS `Post` LEFT JOIN `comments` AS `Comments` ON `Comments`.`post_id` = `Post`.`id` ORDER BY `Post`.`id` desc LIMIT 20 I've searched this group as well as Google and haven't really found much of anything about this. --~--~-~--~~~---~--~~ 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 hasMany/belongsTo relationships - not returning related records.
On Jul 24, 10:10 pm, "mariusz.lewandowski" wrote: > I'm also looking for some convinient way to avoid invoking "bindModel" > method .. I'll tell you what fixed my problem, it was giving the model file the correct extension. My comment model file was named comment.ctp not comment.php :-/ --~--~-~--~~~---~--~~ 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 hasMany/belongsTo relationships - not returning related records.
I'm also looking for some convinient way to avoid invoking "bindModel" method .. On Jul 23, 1:52 pm, Alastair wrote: > Hi and many thanks for your help! > > This did work, however it doesn't make sense that I've had to do this > in the first place! It seems like accessing the parent model of a > child model is broken. I don't know if I'm doing something completely > wrong but I can access my comments records from the user perfectly > fine but am unable to access the User from a comment? > > Does anyone have any suggestions why this might be? > > Cheers, > > Alastair > > On Jul 23, 8:53 am, "mariusz.lewandowski" wrote: > > > I had the same issue. > > > The resolutions goes like that: in beforeFilter i invoke: > > > public function beforeFilter() { > > $this->pageTitle = 'Portfolio'; > > $this->Portfolio->bindModel(array( > > 'belongsTo' => > > array('Category'), > > 'hasMany' => > > array('Image'))); > > } > > > And then you have an access to allrelatedmodels. > > > Cheers. > > > On 22 Lip, 19:11, Alastair wrote: > > > > Hoping someone can suggest something here! > > > > I have a number of models, which look as follows: > > > > Comment > > > -- > > > > class Comment extends AppModel > > > { > > > > var $name = 'Comment'; > > > var $validate = array( > > > 'body' => array('rule' => 'notEmpty') > > > ); > > > > var $belongsTo = array( > > > 'User' => array( > > > 'className' => 'User', > > > 'foreignKey' => 'user_id', > > > ), > > > 'Post' => array( > > > 'className' => 'Post', > > > 'foreignKey' => 'post_id', > > > ), > > > ); > > > > } > > > > Post > > > --- > > > > class Post extends AppModel > > > { > > > > var $name = 'Post'; > > > var $validate = array( > > > 'title' => array('rule' => 'notEmpty'), > > > 'body' => array('rule' => 'notEmpty') > > > ); > > > > var $hasMany = array('Comment'); > > > > } > > > > User > > > --- > > > > class User extends AppModel { > > > > var $actsAs = array('Acl' => array('requester')); > > > var $hasOne = 'Member'; > > > var $name = 'User'; > > > > var $belongsTo = array('Group'); > > > > var $hasMany = array( > > > 'Comment' => array( > > > 'className' => 'Comment', > > > 'foreignKey' => 'user_id' > > > ) > > > ); > > > > } > > > > I'm calling the following find in my Posts controller: > > > > $comments = $this->Comment->find('all', array('recursive' => 2)); > > > > I've declared var $uses = array('Post', 'Comment','User'); at the top > > > of the posts controller. > > > > All I'm getting returned is an array of comments but not theirrelated > > > users. > > > > Can anyone suggest why this might be? > > > > Many thanks! > > > > Alastair --~--~-~--~~~---~--~~ 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 hasMany/belongsTo relationships - not returning related records.
Hi and many thanks for your help! This did work, however it doesn't make sense that I've had to do this in the first place! It seems like accessing the parent model of a child model is broken. I don't know if I'm doing something completely wrong but I can access my comments records from the user perfectly fine but am unable to access the User from a comment? Does anyone have any suggestions why this might be? Cheers, Alastair On Jul 23, 8:53 am, "mariusz.lewandowski" wrote: > I had the same issue. > > The resolutions goes like that: in beforeFilter i invoke: > > public function beforeFilter() { > $this->pageTitle = 'Portfolio'; > $this->Portfolio->bindModel(array( > 'belongsTo' => > array('Category'), > 'hasMany' => array('Image'))); > } > > And then you have an access to all related models. > > Cheers. > > On 22 Lip, 19:11, Alastair wrote: > > > > > Hoping someone can suggest something here! > > > I have a number of models, which look as follows: > > > Comment > > -- > > > class Comment extends AppModel > > { > > > var $name = 'Comment'; > > var $validate = array( > > 'body' => array('rule' => 'notEmpty') > > ); > > > var $belongsTo = array( > > 'User' => array( > > 'className' => 'User', > > 'foreignKey' => 'user_id', > > ), > > 'Post' => array( > > 'className' => 'Post', > > 'foreignKey' => 'post_id', > > ), > > ); > > > } > > > Post > > --- > > > class Post extends AppModel > > { > > > var $name = 'Post'; > > var $validate = array( > > 'title' => array('rule' => 'notEmpty'), > > 'body' => array('rule' => 'notEmpty') > > ); > > > var $hasMany = array('Comment'); > > > } > > > User > > --- > > > class User extends AppModel { > > > var $actsAs = array('Acl' => array('requester')); > > var $hasOne = 'Member'; > > var $name = 'User'; > > > var $belongsTo = array('Group'); > > > var $hasMany = array( > > 'Comment' => array( > > 'className' => 'Comment', > > 'foreignKey' => 'user_id' > > ) > > ); > > > } > > > I'm calling the following find in my Posts controller: > > > $comments = $this->Comment->find('all', array('recursive' => 2)); > > > I've declared var $uses = array('Post', 'Comment','User'); at the top > > of the posts controller. > > > All I'm getting returned is an array of comments but not their related > > users. > > > Can anyone suggest why this might be? > > > Many thanks! > > > Alastair --~--~-~--~~~---~--~~ 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 hasMany/belongsTo relationships - not returning related records.
I had the same issue. The resolutions goes like that: in beforeFilter i invoke: public function beforeFilter() { $this->pageTitle = 'Portfolio'; $this->Portfolio->bindModel(array( 'belongsTo' => array('Category'), 'hasMany' => array('Image'))); } And then you have an access to all related models. Cheers. On 22 Lip, 19:11, Alastair wrote: > Hoping someone can suggest something here! > > I have a number of models, which look as follows: > > Comment > -- > > class Comment extends AppModel > { > > var $name = 'Comment'; > var $validate = array( > 'body' => array('rule' => 'notEmpty') > ); > > var $belongsTo = array( > 'User' => array( > 'className' => 'User', > 'foreignKey' => 'user_id', > ), > 'Post' => array( > 'className' => 'Post', > 'foreignKey' => 'post_id', > ), > ); > > } > > Post > --- > > class Post extends AppModel > { > > var $name = 'Post'; > var $validate = array( > 'title' => array('rule' => 'notEmpty'), > 'body' => array('rule' => 'notEmpty') > ); > > var $hasMany = array('Comment'); > > } > > User > --- > > class User extends AppModel { > > var $actsAs = array('Acl' => array('requester')); > var $hasOne = 'Member'; > var $name = 'User'; > > var $belongsTo = array('Group'); > > var $hasMany = array( > 'Comment' => array( > 'className' => 'Comment', > 'foreignKey' => 'user_id' > ) > ); > > } > > I'm calling the following find in my Posts controller: > > $comments = $this->Comment->find('all', array('recursive' => 2)); > > I've declared var $uses = array('Post', 'Comment','User'); at the top > of the posts controller. > > All I'm getting returned is an array of comments but not their related > users. > > Can anyone suggest why this might be? > > Many thanks! > > Alastair --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with hasMany/belongsTo relationships - not returning related records.
Hoping someone can suggest something here! I have a number of models, which look as follows: Comment -- class Comment extends AppModel { var $name = 'Comment'; var $validate = array( 'body' => array('rule' => 'notEmpty') ); var $belongsTo = array( 'User' => array( 'className' => 'User', 'foreignKey' => 'user_id', ), 'Post' => array( 'className' => 'Post', 'foreignKey' => 'post_id', ), ); } Post --- class Post extends AppModel { var $name = 'Post'; var $validate = array( 'title' => array('rule' => 'notEmpty'), 'body' => array('rule' => 'notEmpty') ); var $hasMany = array('Comment'); } User --- class User extends AppModel { var $actsAs = array('Acl' => array('requester')); var $hasOne = 'Member'; var $name = 'User'; var $belongsTo = array('Group'); var $hasMany = array( 'Comment' => array( 'className' => 'Comment', 'foreignKey' => 'user_id' ) ); } I'm calling the following find in my Posts controller: $comments = $this->Comment->find('all', array('recursive' => 2)); I've declared var $uses = array('Post', 'Comment','User'); at the top of the posts controller. All I'm getting returned is an array of comments but not their related users. Can anyone suggest why this might be? Many thanks! Alastair --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ActAs in hasMany/belongsTo relationship doesn't work?
Hi! I'm using behavior: http://bakery.cakephp.org/articles/view/actas-image-column-behavior So. It's looks like: Model A actAs ('Image'...) Model A hasMany Model B Model B belongsTo Model A ... So, when I do some thing like Model A->find('all') - all fine. Behavior work fine, and I get my images as I wanted. But, when I try to use $this->Model B->Model A->find('all..) behavior doesn't work When I try $this->Model-B->find(...) behavior doesn't work Where I'm wrong? I whant to make select from Model B and getting related Model A with working behavior... Where is my mistake? Cake 1.2.3.8166 Help --~--~-~--~~~---~--~~ 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: hasMany + belongsTo relationship problem
that worked. thank you very much On 12 Gen, 19:42, Webweave wrote: > You just need to set the recursive level to fetch the data that is not > directly related. See:http://book.cakephp.org/view/439/recursive > > Set it before you do your find, or in the individual action. > > On Jan 8, 11:20 pm, Ernesto wrote: > > > > > Hello and thx for the fast response. > > > i forgot to paste the var $primaryKey in my model's code. sorry. > > > everything is working fine in my app. i just can't fetch Location > > Types starting from persons. i'll take a look @ containable behaviour. > > > thx again > > > On 8 Gen, 21:43, Webweave wrote: > > > > Since you are using "non-standard" names for your ID columns, you need > > > to specify $primaryKey in your models, so your Person model, you would > > > need: > > > > $primaryKey = 'location_id'; > > > > If you set debug to 2 or 3, you'll see the queries being executed. You > > > may need to set recursive to get the non-related data too, see: > > > > On Jan 8, 8:09 am, Ernesto wrote: > > > > > Hello. > > > > > i have 3 models > > > > - Person > > > > - Location > > > > - Location_Type > > > > > pointing respectively @ 3 tables: > > > > > Persons: > > > > person_id > > > > name > > > > surname > > > > > Locations: > > > > location_id > > > > person_id > > > > location_type_id > > > > address > > > > country > > > > > Location_Types: > > > > location_type_id > > > > description > > > > > the 3 models are linked as follow: > > > > Person hasMany Location > > > > Location belongsTo Location_Type > > > > > here's the models' code > > > > > class person extends AppModel { > > > > var $hasMany = array( > > > > "Locations" => array( > > > > "className" => "Location", > > > > "foreignKey" => "location_id", > > > > "dependent" => "true" > > > > ) > > > > ); > > > > > } > > > > > class location extends AppModel { > > > > var $belongsTo = array( > > > > "Location_Type" => array( > > > > "className" => "LocationType", > > > > "foreignKey" => "location_type_id", > > > > "dependent" => "true" > > > > ) > > > > ); > > > > > } > > > > > I can't find out why the "Location_Type"'s data is not showing when i > > > > load data from the "Person" model --~--~-~--~~~---~--~~ 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: hasMany + belongsTo relationship problem
You just need to set the recursive level to fetch the data that is not directly related. See: http://book.cakephp.org/view/439/recursive Set it before you do your find, or in the individual action. On Jan 8, 11:20 pm, Ernesto wrote: > Hello and thx for the fast response. > > i forgot to paste the var $primaryKey in my model's code. sorry. > > everything is working fine in my app. i just can't fetch Location > Types starting from persons. i'll take a look @ containable behaviour. > > thx again > > On 8 Gen, 21:43, Webweave wrote: > > > Since you are using "non-standard" names for your ID columns, you need > > to specify $primaryKey in your models, so your Person model, you would > > need: > > > $primaryKey = 'location_id'; > > > If you set debug to 2 or 3, you'll see the queries being executed. You > > may need to set recursive to get the non-related data too, see: > > > On Jan 8, 8:09 am, Ernesto wrote: > > > > Hello. > > > > i have 3 models > > > - Person > > > - Location > > > - Location_Type > > > > pointing respectively @ 3 tables: > > > > Persons: > > > person_id > > > name > > > surname > > > > Locations: > > > location_id > > > person_id > > > location_type_id > > > address > > > country > > > > Location_Types: > > > location_type_id > > > description > > > > the 3 models are linked as follow: > > > Person hasMany Location > > > Location belongsTo Location_Type > > > > here's the models' code > > > > class person extends AppModel { > > > var $hasMany = array( > > > "Locations" => array( > > > "className" => "Location", > > > "foreignKey" => "location_id", > > > "dependent" => "true" > > > ) > > > ); > > > > } > > > > class location extends AppModel { > > > var $belongsTo = array( > > > "Location_Type" => array( > > > "className" => "LocationType", > > > "foreignKey" => "location_type_id", > > > "dependent" => "true" > > > ) > > > ); > > > > } > > > > I can't find out why the "Location_Type"'s data is not showing when i > > > load data from the "Person" model > > --~--~-~--~~~---~--~~ 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: hasMany + belongsTo relationship problem
Hello and thx for the fast response. i forgot to paste the var $primaryKey in my model's code. sorry. everything is working fine in my app. i just can't fetch Location Types starting from persons. i'll take a look @ containable behaviour. thx again On 8 Gen, 21:43, Webweave wrote: > Since you are using "non-standard" names for your ID columns, you need > to specify $primaryKey in your models, so your Person model, you would > need: > > $primaryKey = 'location_id'; > > If you set debug to 2 or 3, you'll see the queries being executed. You > may need to set recursive to get the non-related data too, see: > > On Jan 8, 8:09 am, Ernesto wrote: > > > > > Hello. > > > i have 3 models > > - Person > > - Location > > - Location_Type > > > pointing respectively @ 3 tables: > > > Persons: > > person_id > > name > > surname > > > Locations: > > location_id > > person_id > > location_type_id > > address > > country > > > Location_Types: > > location_type_id > > description > > > the 3 models are linked as follow: > > Person hasMany Location > > Location belongsTo Location_Type > > > here's the models' code > > > class person extends AppModel { > > var $hasMany = array( > > "Locations" => array( > > "className" => "Location", > > "foreignKey" => "location_id", > > "dependent" => "true" > > ) > > ); > > > } > > > class location extends AppModel { > > var $belongsTo = array( > > "Location_Type" => array( > > "className" => "LocationType", > > "foreignKey" => "location_type_id", > > "dependent" => "true" > > ) > > ); > > > } > > > I can't find out why the "Location_Type"'s data is not showing when i > > load data from the "Person" model --~--~-~--~~~---~--~~ 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: hasMany + belongsTo relationship problem
Since you are using "non-standard" names for your ID columns, you need to specify $primaryKey in your models, so your Person model, you would need: $primaryKey = 'location_id'; If you set debug to 2 or 3, you'll see the queries being executed. You may need to set recursive to get the non-related data too, see: On Jan 8, 8:09 am, Ernesto wrote: > Hello. > > i have 3 models > - Person > - Location > - Location_Type > > pointing respectively @ 3 tables: > > Persons: > person_id > name > surname > > Locations: > location_id > person_id > location_type_id > address > country > > Location_Types: > location_type_id > description > > the 3 models are linked as follow: > Person hasMany Location > Location belongsTo Location_Type > > here's the models' code > > class person extends AppModel { > var $hasMany = array( > "Locations" => array( > "className" => "Location", > "foreignKey" => "location_id", > "dependent" => "true" > ) > ); > > } > > class location extends AppModel { > var $belongsTo = array( > "Location_Type" => array( > "className" => "LocationType", > "foreignKey" => "location_type_id", > "dependent" => "true" > ) > ); > > } > > I can't find out why the "Location_Type"'s data is not showing when i > load data from the "Person" model --~--~-~--~~~---~--~~ 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: hasMany + belongsTo relationship problem
Table names are lower_case_undescored_plural while model names are FirstCapsSingular, so: your tables should be: - persons --- id <--- using id as primary key makes your life a lot easier --- name --- surname - locations --- id --- person_id --- location_type_id --- address --- country - location_types --- id --- description then your models would be: class Person { var $hasMany = array('Location'); } class Location { var $belongsTo = array('Person','LocationType'); } class LocationType { var $hasMany = array('Location'); } Now that just makes your models compliant to the conventions and your life a lot easier. But still LocationType will not show up when fecth Person data and that is because it is not directly related to the Person model. The best way to do this is using the Containable behavior http://book.cakephp.org/view/474/Containable Ernesto wrote: > Hello. > > i have 3 models > - Person > - Location > - Location_Type > > pointing respectively @ 3 tables: > > Persons: > person_id > name > surname > > Locations: > location_id > person_id > location_type_id > address > country > > Location_Types: > location_type_id > description > > the 3 models are linked as follow: > Person hasMany Location > Location belongsTo Location_Type > > here's the models' code > > class person extends AppModel { > var $hasMany = array( > "Locations" => array( > "className" => "Location", > "foreignKey" => "location_id", > "dependent" => "true" > ) > ); > } > > class location extends AppModel { > var $belongsTo = array( > "Location_Type" => array( > "className" => "LocationType", > "foreignKey" => "location_type_id", > "dependent" => "true" > ) > ); > } > > I can't find out why the "Location_Type"'s data is not showing when i > load data from the "Person" model > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasMany + belongsTo relationship problem
Hello. i have 3 models - Person - Location - Location_Type pointing respectively @ 3 tables: Persons: person_id name surname Locations: location_id person_id location_type_id address country Location_Types: location_type_id description the 3 models are linked as follow: Person hasMany Location Location belongsTo Location_Type here's the models' code class person extends AppModel { var $hasMany = array( "Locations" => array( "className" => "Location", "foreignKey" => "location_id", "dependent" => "true" ) ); } class location extends AppModel { var $belongsTo = array( "Location_Type" => array( "className" => "LocationType", "foreignKey" => "location_type_id", "dependent" => "true" ) ); } I can't find out why the "Location_Type"'s data is not showing when i load data from the "Person" model --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasMany/belongsTo w/ more than one foreign keys?
Hello, Just came across a case where hasMany/belongsTo relations requires more than one foreign keys from the same model. Take a wish list for instance. There's two models, User and Wish. A user can have multiple wishes for him self for sure. And he/she can pick up others' wishes and claim a exclusive right to help fullful them. Vice versa on Wish model's part. In 'wishes' table in DB, there's two foreign keys: 'user_id' indicating the owner of a wish, and 'claim_by' indicating the kind- hearted claimer. Looked into some documents and make the following code, which doesn't work. Looking for help here :) BTW, do you think HABTM is a better solution in such a case like this? array( 'className' => 'Wish', 'foreignKey' => 'user_id'), 'ClaimedItem' => array( 'className' => 'Wish', 'foreignKey' => 'claim_by' ), ); } ?> array( 'className' => 'User', 'foreignKey' => 'user_id'), 'Claimer' => array( 'className' => 'User', 'foreignKey' => 'claim_by' ) ); } ?> --~--~-~--~~~---~--~~ 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: SOLVED Re: cake is ignoring my hasMany/belongsTo (noob)
On Feb 7, 2008 1:30 PM, sbeam <[EMAIL PROTECTED]> wrote: > > sorry folks I had model/project.php named as model/projects.php - I > finally realized Cake was ignoring the whole thing, without > complaining. So moral of the story - watch your cases and inflections! > just like ROR, figuring out what should be plural/singular or > camelCase/under_score_separated is a PITA (esp. for noobs) > Learn them http://manual.cakephp.org/appendix/conventions Live them http://tempdocs.cakephp.org/#TOC20140 when starting out you will be much happier. When you get the real feel of the framework then break them bust em and really stretch them -- -- (the old fart) the advice is free, the lack of crankiness will cost you - its a fine line between a real question and an idiot http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/ http://blog.samdevore.com/cakephp-pages/my-cake-wont-bake/ http://blog.samdevore.com/cakephp-pages/i-cant-bake --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
SOLVED Re: cake is ignoring my hasMany/belongsTo (noob)
sorry folks I had model/project.php named as model/projects.php - I finally realized Cake was ignoring the whole thing, without complaining. So moral of the story - watch your cases and inflections! just like ROR, figuring out what should be plural/singular or camelCase/under_score_separated is a PITA (esp. for noobs) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
cake is ignoring my hasMany/belongsTo (noob)
I am starting out with Cake after messing with RoR for a while. I jumped right in with a project where 'ArtWorks' are organized into 'Projects'. I wrote it all thusly: === class Project extends AppModel { var $hasMany = array('PubWorks' => array('className' => 'ArtWork', 'foreignKey'=> 'project_id', 'dependent' => true, 'exclusive' => false)); } - class ArtWork extends AppModel { var $belongsTo = array('Project' => array('className' => 'Project', 'foreignKey' => 'project_id' ) ); } class ProjectsController extends AppController { function show($id) { $w = $this->Project->read(); print "DEBUG: at line " . __LINE__ . ' of ' . __FILE__ . "\n"; print_r($w); print ''; } } = I have set up the DB correctly with FKs using mySQL InnoDB. And entered some sample data. But when I call http://localhost/projects/show/2 I get the debug dump of: DEBUG: at line 8 of /xxx/cake_1.2.0.6311-beta/app/controllers/ projects_controller.php Array ( [Project] => Array ( [id] => 2 [name] => War Room [begin_date] => -00-00 ) ) = no sign of the ArtWorks belonging to the Project. The SQL dumps show the artworks table was never queried. I am out of ideas, according to the manual this should work right? What am I missing? thanks Sam --~--~-~--~~~---~--~~ 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: Using Cake model relations (hasMany, belongsTo, etc)
Another alternative. In your comments controller, add var $recursion = 2; Then modify your app/views/comments/index.thtml changing this: to this: Jeff On Sep 24, 9:41 am, jwerd <[EMAIL PROTECTED]> wrote: > Notice (8): Undefined index: username [CORE/notes/views/notes/ > view.ctp, line 80] > > I think the complex part is that I'm trying to do this through my > notes view, because that's where it will list the connecting followups > and then I need it to refrence the user_id to the username, etc. :( > > Array ( [id] => 13 [comment] => Should we have limits on the amount of > trades per month. People could begin to conduct business this way and > it might pose a problem. [note_id] => 21 [user_id] => 1 [created] => > 2007-09-23 16:42:22 ) > > On Sep 24, 9:18 am, Marco <[EMAIL PROTECTED]> wrote: > > > If I undestood wll your need, it should be enough to define 'username' > > as displayField for the user model: > > > model user > > var $displayField = 'username'; > > User hasMany Note > > User hasMany Followup > > > On 24 Set, 16:44, jwerd <[EMAIL PROTECTED]> wrote: > > > > I'm using 1.2.x (latest SVN from trunk) fyi. > > > > Anyways I've set up a notes system to keep track of my notes > > > internally, which is scaling to be quite efficient for what I need / > > > what. Now here is my dilema. I have three tables: > > > > notes > > > id > > > title > > > body > > > created > > > user_id > > > > users > > > id > > > username > > > password > > > > followups > > > id > > > comment > > > user_id > > > note_id > > > created > > > > I believe I'm following the Cake style table layout and structure > > > because most of my relations work. The followups table is supposed to > > > like comments on the note. > > > > Anyways when I'm viewing a note that has follow ups it appears below > > > the note's properties and says Related Followups and it's a list of > > > all the connected followups to that note. Now the thing is here is > > > what it looks like (from scaffolding) > > > > |Comment| --- | User | Note | Action > > > | > > > |This is doable, don't worry | 1 | 1 | View, > > > Edit, Delete | > > > > The problem is, I can't seem to change that 1 to the actual username > > > and I'm not sure how without writing a custom sql query to handle the > > > entire fetching of the followups to notes relationship. > > > > Can someone please help me out? Here's my cake relationship layout > > > > model user > > > User hasMany Note > > > User hasMany Followup > > > > model followup > > > Followup belongsTo Note > > > Followup belongsTo User > > > > model note > > > Note belongsTo User > > > Note hasMany Followup > > > > I'm not asking for someone to completely write my script just to lend > > > a helping hand as to if it's doable with the cake relations or do I > > > have to custom query this certain thign I want. > > > > thanks for your time appreciate any response i get. --~--~-~--~~~---~--~~ 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: Using Cake model relations (hasMany, belongsTo, etc)
Notice (8): Undefined index: username [CORE/notes/views/notes/ view.ctp, line 80] I think the complex part is that I'm trying to do this through my notes view, because that's where it will list the connecting followups and then I need it to refrence the user_id to the username, etc. :( Array ( [id] => 13 [comment] => Should we have limits on the amount of trades per month. People could begin to conduct business this way and it might pose a problem. [note_id] => 21 [user_id] => 1 [created] => 2007-09-23 16:42:22 ) On Sep 24, 9:18 am, Marco <[EMAIL PROTECTED]> wrote: > If I undestood wll your need, it should be enough to define 'username' > as displayField for the user model: > > model user > var $displayField = 'username'; > User hasMany Note > User hasMany Followup > > On 24 Set, 16:44, jwerd <[EMAIL PROTECTED]> wrote: > > > I'm using 1.2.x (latest SVN from trunk) fyi. > > > Anyways I've set up a notes system to keep track of my notes > > internally, which is scaling to be quite efficient for what I need / > > what. Now here is my dilema. I have three tables: > > > notes > > id > > title > > body > > created > > user_id > > > users > > id > > username > > password > > > followups > > id > > comment > > user_id > > note_id > > created > > > I believe I'm following the Cake style table layout and structure > > because most of my relations work. The followups table is supposed to > > like comments on the note. > > > Anyways when I'm viewing a note that has follow ups it appears below > > the note's properties and says Related Followups and it's a list of > > all the connected followups to that note. Now the thing is here is > > what it looks like (from scaffolding) > > > |Comment| --- | User | Note | Action > > | > > |This is doable, don't worry | 1 | 1 | View, > > Edit, Delete | > > > The problem is, I can't seem to change that 1 to the actual username > > and I'm not sure how without writing a custom sql query to handle the > > entire fetching of the followups to notes relationship. > > > Can someone please help me out? Here's my cake relationship layout > > > model user > > User hasMany Note > > User hasMany Followup > > > model followup > > Followup belongsTo Note > > Followup belongsTo User > > > model note > > Note belongsTo User > > Note hasMany Followup > > > I'm not asking for someone to completely write my script just to lend > > a helping hand as to if it's doable with the cake relations or do I > > have to custom query this certain thign I want. > > > thanks for your time appreciate any response i get. --~--~-~--~~~---~--~~ 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: Using Cake model relations (hasMany, belongsTo, etc)
If I undestood wll your need, it should be enough to define 'username' as displayField for the user model: model user var $displayField = 'username'; User hasMany Note User hasMany Followup On 24 Set, 16:44, jwerd <[EMAIL PROTECTED]> wrote: > I'm using 1.2.x (latest SVN from trunk) fyi. > > Anyways I've set up a notes system to keep track of my notes > internally, which is scaling to be quite efficient for what I need / > what. Now here is my dilema. I have three tables: > > notes > id > title > body > created > user_id > > users > id > username > password > > followups > id > comment > user_id > note_id > created > > I believe I'm following the Cake style table layout and structure > because most of my relations work. The followups table is supposed to > like comments on the note. > > Anyways when I'm viewing a note that has follow ups it appears below > the note's properties and says Related Followups and it's a list of > all the connected followups to that note. Now the thing is here is > what it looks like (from scaffolding) > > |Comment| --- | User | Note | Action > | > |This is doable, don't worry | 1 | 1 | View, > Edit, Delete | > > The problem is, I can't seem to change that 1 to the actual username > and I'm not sure how without writing a custom sql query to handle the > entire fetching of the followups to notes relationship. > > Can someone please help me out? Here's my cake relationship layout > > model user > User hasMany Note > User hasMany Followup > > model followup > Followup belongsTo Note > Followup belongsTo User > > model note > Note belongsTo User > Note hasMany Followup > > I'm not asking for someone to completely write my script just to lend > a helping hand as to if it's doable with the cake relations or do I > have to custom query this certain thign I want. > > thanks for your time appreciate any response i get. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Using Cake model relations (hasMany, belongsTo, etc)
I'm using 1.2.x (latest SVN from trunk) fyi. Anyways I've set up a notes system to keep track of my notes internally, which is scaling to be quite efficient for what I need / what. Now here is my dilema. I have three tables: notes id title body created user_id users id username password followups id comment user_id note_id created I believe I'm following the Cake style table layout and structure because most of my relations work. The followups table is supposed to like comments on the note. Anyways when I'm viewing a note that has follow ups it appears below the note's properties and says Related Followups and it's a list of all the connected followups to that note. Now the thing is here is what it looks like (from scaffolding) |Comment| --- | User | Note | Action | |This is doable, don't worry | 1 | 1 | View, Edit, Delete | The problem is, I can't seem to change that 1 to the actual username and I'm not sure how without writing a custom sql query to handle the entire fetching of the followups to notes relationship. Can someone please help me out? Here's my cake relationship layout model user User hasMany Note User hasMany Followup model followup Followup belongsTo Note Followup belongsTo User model note Note belongsTo User Note hasMany Followup I'm not asking for someone to completely write my script just to lend a helping hand as to if it's doable with the cake relations or do I have to custom query this certain thign I want. thanks for your time appreciate any response i get. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Recursive finds with hasMany/belongsTo
I apologize if I'm just not finding the right posts in the archives, but I'm having a problem I'm guessing some of you have had an might know the answer to. I've got two models setup as follows: models/incident.php: var $hasMany = array( 'Resident' => array('className' => 'Resident', 'foreignKey' => 'incident_id')); models/resident.php: var $belongsTo = array( 'Incident' => array('className' => 'Incident', 'foreignKey' => 'incident_id')); I'm trying to search for any incidents with residents who have a given campus id. So, in my incident controller, I'm trying to do this: $this->Incident->findAll(array("Resident.campusid" => "123456", '', '', '', 1, 2)); When I try this though, rather than recognizing Resident as an associated model, it just plugs it in as a table name and I receive a SQL error. When I remove the search condition (and just do a recursive search), it finds the associated resident just fine. Any guesses on what I might be doing wrong to not have the ability to search by this associated model? Thanks a bunch and hopefully this isn't something that gets asked all the time! Nathan --~--~-~--~~~---~--~~ 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: hasMany / belongsTo relationship help
Here is the answer, in add() I put - $this->ArticleComment->Article->id = $article_id; $this->set('comment', $this->ArticleComment->Article->read()); Thanks for the help folks ;) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasMany / belongsTo relationship help
Its a simple relationship, One article has many comments. I don't even have users, just simply type in your name. I cannot figuere out how to access the Article Data from within the ArticleComment What do I need to do in the add() method to get it to load a list of comments using the article_id? How would I get this add() method to work, in general? And if you were wondering my, end goal is to learn the CakePHP system. Getting this to work is secondary. -- ArticleComment model - var $belongsTo = array('Article' => array('className' => 'Article', 'conditions' => '', 'order' => '', 'foreignKey' => 'article_id' ) ); ArticleCommentController -- class ArticleCommentController extends AppController { var $useTable = 'article_comment'; var $name = 'ArticleComment'; function add($article_id) { $this->ArticleComment->article_id = $article_id; $this->set('comment', $this->ArticleComment->read()); if (!empty($this->data)) { $this->data['ArticleComment']['date'] = $this->data['ArticleComment']['date_year'] . "-" . $this->data['ArticleComment']['date_month'] . "-" . $this->data['ArticleComment']['date_day']; if ($this->Article->save($this->data)) { $this->flash('Your comment has been saved.', '/ article'); } } } } --~--~-~--~~~---~--~~ 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: hasMany/belongsTo
Uuummm, I must say I don't really understand what your problem precisely is, however I can spot a few mistakes in the code you provided; * using the HtmlHelper the tagName param should be User/id, not User/ user_id (that's if you're using the cake naming conventions) * also if your relations are defined properly, you shouldn't have to $this->data['User']['profile_id']=array($this->Profile- >getLastInsertId()); if I understand your app properly (Please, provide more details!) you should have something like this for a one to one relationship; User Model: $hasOne = array('Profile'); Profile Model: $belongsTo = array('User'); However, I see you have a Users_Profiles, meaning your having a many to many relationship...??! If that's the case, make sure your table is named Profiles_Users (alphabetical) and you should not have a profile_id in the user table nor in the user model. Then try that; (assuming you have used the proper naming conv...!) User Model: var $hasAndBelongsToMany = array('Profile'); and the Profile Model should have the reverse; var $hasAnd BelongsToMany = array('User'); So anyway, again, I'm really not sure where you're heading... but post some more code (models, views and tbl structure) and we'll see what we can do! Hope it helps! Seb./ Kathrin wrote: > Hello, > ich have Problems to save data in a hasMany/belonsto > Users_ProfilesTable. > Sie Array is OK. > My source: > > View User: > hidden('User/user_id', array('value' => > $post['User']['id']));?> > post to User/Controller save the data and post user_id to Profile/ > controller > View/Profile > echo $form->hidden('User/user_id', array('value'=> $userid)); > Controller/Profile > function addprofile($userid=0) { > $this->set('userid',$userid); > if (!empty ($this->data)) { #Formular wurde > abgeschickt->eingegebene Datenspeichern > $this->cleanUpFields(); > $this->Profile->create(); > > $this->data['Profile']['user_id']=array($this->data['User'] > ['user_id']); > $this->Profile->save($this->data); > $this->data['User']['profile_id']=array($this->Profile- > >getLastInsertId()); > //error_log(print_r($this->data,true)); > $this->Session->setFlash('The Profile-Data has been > saved'); > exit(); > } > Have somebody an idea? > Sincerely Kathrin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasMany/belongsTo
Hello, ich have Problems to save data in a hasMany/belonsto Users_ProfilesTable. Sie Array is OK. My source: View User: hidden('User/user_id', array('value' => $post['User']['id']));?> post to User/Controller save the data and post user_id to Profile/ controller View/Profile echo $form->hidden('User/user_id', array('value'=> $userid)); Controller/Profile function addprofile($userid=0) { $this->set('userid',$userid); if (!empty ($this->data)) { #Formular wurde abgeschickt->eingegebene Datenspeichern $this->cleanUpFields(); $this->Profile->create(); $this->data['Profile']['user_id']=array($this->data['User'] ['user_id']); $this->Profile->save($this->data); $this->data['User']['profile_id']=array($this->Profile- >getLastInsertId()); //error_log(print_r($this->data,true)); $this->Session->setFlash('The Profile-Data has been saved'); exit(); } Have somebody an idea? Sincerely Kathrin --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
There is something strange here. I found where problem is. In file cake/libs/model/datasources/dbo_source.php on line 588: if (isset($db) && $db != null) { This condition is _always_ false on my system. When I changed it to if (isset($db) || $db != null) { all begin to work fine. Seems like a error in my php version. I use php 5.2.0.0. Will try to download more recent and test with it. On 13 фев, 23:09, "alexxwiz" <[EMAIL PROTECTED]> wrote: > I'm glad for you, but my problem is still here :( > Can someone point me where is my mistake? > > On 13 фев, 18:00, "shoesole" <[EMAIL PROTECTED]> wrote: > > > Wow. I knew it had to be something easy that I was completely > > overlooking. Thank you so much Eric. I read the manual chapter on > > models multiple times, but I guess that part just didn't sink in > > (maybe next time I should read more carefully). Anyway, Thanks. This > > is my first shot at Cake and I love it so far, but that really had me > > confounded. > > > > > I have same problem. > > > Two tables: > > > > > > CREATE TABLE `maincats` ( > > > `id` int(10) unsigned NOT NULL auto_increment, > > > `title` varchar(255) default NULL, > > > `visible` tinyint(4) NOT NULL default '1', > > > `created` datetime NOT NULL, > > > PRIMARY KEY (`id`) > > > ) ENGINE=MyISAM; > > > > > > CREATE TABLE `categories` ( > > > `id` int(10) unsigned NOT NULL auto_increment, > > > `title` varchar(255) default NULL, > > > `maincat_id` int(11) default NULL, > > > `visible` tinyint(4) NOT NULL default '1', > > > `created` datetime NOT NULL, > > > PRIMARY KEY (`id`) > > > ) ENGINE=MyISAM; > > > > > > Two models: > > > > > > class Maincat extends AppModel { > > > var $name = 'Maincat'; > > > var $hasMany = > > > array('Category'=>array('className'=>'Category','foreignKey' => > > > 'maincat_id')); > > > > > > } > > > > > > class Category extends AppModel { > > > var $name = 'Category'; > > > > > > } > > > > > > print_r($this->Maincat->findAll()); > > > > > > returns only maincats content and none sub-categories. > > > > > > Array > > > ( > > > [0] => Array > > > ( > > > [Maincat] => Array > > > ( > > > [id] => 1 > > > [title] => Some first > > > [visible] => 1 > > > [created] => 2007-02-13 14:39:28 > > > ) > > > > > > ) > > > > > > [1] => Array > > > ( > > > [Maincat] => Array > > > ( > > > [id] => 2 > > > [title] => Some second > > > [visible] => 1 > > > [created] => 2007-02-13 00:00:00 > > > ) > > > > > > ) > > > > > > ) > > > > > > Where is my mistake? --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
I'm glad for you, but my problem is still here :( Can someone point me where is my mistake? On 13 фев, 18:00, "shoesole" <[EMAIL PROTECTED]> wrote: > Wow. I knew it had to be something easy that I was completely > overlooking. Thank you so much Eric. I read the manual chapter on > models multiple times, but I guess that part just didn't sink in > (maybe next time I should read more carefully). Anyway, Thanks. This > is my first shot at Cake and I love it so far, but that really had me > confounded. --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
Wow. I knew it had to be something easy that I was completely overlooking. Thank you so much Eric. I read the manual chapter on models multiple times, but I guess that part just didn't sink in (maybe next time I should read more carefully). Anyway, Thanks. This is my first shot at Cake and I love it so far, but that really had me confounded. --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
Added to Category model: var $belongsTo = array ( 'Maincat' => array ( 'className' => 'Maincat', 'foreignKey' => 'maincat_id' ) ); Trying to set recursive to 1 and 2, but nope. $this->Maincat->recursive = 1; print_r($this->Maincat->findAll()); Result is same as before. Any suggestions? On 13 фев, 16:42, "Seb" <[EMAIL PROTECTED]> wrote: > @alexxwiz : try adding this to your Category model; > var $belongsTo = array ('Maincat'); > > @shoesole : note how you don't have to use the className value if you > stick to the naming convention, hence your > var $belongsTo = array('Blog' => array('className' => 'Blog') ); > can become > var $belongsTo = array('Blog'); > > Hope that helps! > > Cheers, > > Seb. > > On Feb 13, 11:27 pm, "alexxwiz" <[EMAIL PROTECTED]> wrote: > > > I have same problem. > > Two tables: > > > CREATE TABLE `maincats` ( > > `id` int(10) unsigned NOT NULL auto_increment, > > `title` varchar(255) default NULL, > > `visible` tinyint(4) NOT NULL default '1', > > `created` datetime NOT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM; > > > CREATE TABLE `categories` ( > > `id` int(10) unsigned NOT NULL auto_increment, > > `title` varchar(255) default NULL, > > `maincat_id` int(11) default NULL, > > `visible` tinyint(4) NOT NULL default '1', > > `created` datetime NOT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM; > > > Two models: > > > class Maincat extends AppModel { > > var $name = 'Maincat'; > > var $hasMany = > > array('Category'=>array('className'=>'Category','foreignKey' => > > 'maincat_id')); > > > } > > > class Category extends AppModel { > > var $name = 'Category'; > > > } > > > print_r($this->Maincat->findAll()); > > > returns only maincats content and none sub-categories. > > > Array > > ( > > [0] => Array > > ( > > [Maincat] => Array > > ( > > [id] => 1 > > [title] => Some first > > [visible] => 1 > > [created] => 2007-02-13 14:39:28 > > ) > > > ) > > > [1] => Array > > ( > > [Maincat] => Array > > ( > > [id] => 2 > > [title] => Some second > > [visible] => 1 > > [created] => 2007-02-13 00:00:00 > > ) > > > ) > > > ) > > > Where is my mistake? --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
@alexxwiz : try adding this to your Category model; var $belongsTo = array ('Maincat'); @shoesole : note how you don't have to use the className value if you stick to the naming convention, hence your var $belongsTo = array('Blog' => array('className' => 'Blog') ); can become var $belongsTo = array('Blog'); Hope that helps! Cheers, Seb. On Feb 13, 11:27 pm, "alexxwiz" <[EMAIL PROTECTED]> wrote: > I have same problem. > Two tables: > > CREATE TABLE `maincats` ( > `id` int(10) unsigned NOT NULL auto_increment, > `title` varchar(255) default NULL, > `visible` tinyint(4) NOT NULL default '1', > `created` datetime NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM; > > CREATE TABLE `categories` ( > `id` int(10) unsigned NOT NULL auto_increment, > `title` varchar(255) default NULL, > `maincat_id` int(11) default NULL, > `visible` tinyint(4) NOT NULL default '1', > `created` datetime NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM; > > Two models: > > class Maincat extends AppModel { > var $name = 'Maincat'; > var $hasMany = > array('Category'=>array('className'=>'Category','foreignKey' => > 'maincat_id')); > > } > > class Category extends AppModel { > var $name = 'Category'; > > } > > print_r($this->Maincat->findAll()); > > returns only maincats content and none sub-categories. > > Array > ( > [0] => Array > ( > [Maincat] => Array > ( > [id] => 1 > [title] => Some first > [visible] => 1 > [created] => 2007-02-13 14:39:28 > ) > > ) > > [1] => Array > ( > [Maincat] => Array > ( > [id] => 2 > [title] => Some second > [visible] => 1 > [created] => 2007-02-13 00:00:00 > ) > > ) > > ) > > Where is my mistake? --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
@alexxwiz.. and make sure you read Eric's post about $recursive! ;) S. On Feb 13, 11:27 pm, "alexxwiz" <[EMAIL PROTECTED]> wrote: > I have same problem. > Two tables: > > CREATE TABLE `maincats` ( > `id` int(10) unsigned NOT NULL auto_increment, > `title` varchar(255) default NULL, > `visible` tinyint(4) NOT NULL default '1', > `created` datetime NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM; > > CREATE TABLE `categories` ( > `id` int(10) unsigned NOT NULL auto_increment, > `title` varchar(255) default NULL, > `maincat_id` int(11) default NULL, > `visible` tinyint(4) NOT NULL default '1', > `created` datetime NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM; > > Two models: > > class Maincat extends AppModel { > var $name = 'Maincat'; > var $hasMany = > array('Category'=>array('className'=>'Category','foreignKey' => > 'maincat_id')); > > } > > class Category extends AppModel { > var $name = 'Category'; > > } > > print_r($this->Maincat->findAll()); > > returns only maincats content and none sub-categories. > > Array > ( > [0] => Array > ( > [Maincat] => Array > ( > [id] => 1 > [title] => Some first > [visible] => 1 > [created] => 2007-02-13 14:39:28 > ) > > ) > > [1] => Array > ( > [Maincat] => Array > ( > [id] => 2 > [title] => Some second > [visible] => 1 > [created] => 2007-02-13 00:00:00 > ) > > ) > > ) > > Where is my mistake? --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
I have same problem. Two tables: CREATE TABLE `maincats` ( `id` int(10) unsigned NOT NULL auto_increment, `title` varchar(255) default NULL, `visible` tinyint(4) NOT NULL default '1', `created` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM; CREATE TABLE `categories` ( `id` int(10) unsigned NOT NULL auto_increment, `title` varchar(255) default NULL, `maincat_id` int(11) default NULL, `visible` tinyint(4) NOT NULL default '1', `created` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM; Two models: class Maincat extends AppModel { var $name = 'Maincat'; var $hasMany = array('Category'=>array('className'=>'Category','foreignKey' => 'maincat_id')); } class Category extends AppModel { var $name = 'Category'; } print_r($this->Maincat->findAll()); returns only maincats content and none sub-categories. Array ( [0] => Array ( [Maincat] => Array ( [id] => 1 [title] => Some first [visible] => 1 [created] => 2007-02-13 14:39:28 ) ) [1] => Array ( [Maincat] => Array ( [id] => 2 [title] => Some second [visible] => 1 [created] => 2007-02-13 00:00:00 ) ) ) Where is my mistake? --~--~-~--~~~---~--~~ 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: Help with a $hasMany, $belongsTo association...
Try this: $this->Blog->recursive = 1; >From http://manual.cakephp.org/chapter/models: $recursive = 0 Cake fetches Group data $recursive = 1 Cake fetches a Group and its associated Users $recursive = 2 Cake fetches a Group, its associated Users, and the Users' associated Articles HTH, Eric On 2/12/07, shoesole <[EMAIL PROTECTED]> wrote: > > > Okay, I think this should work, but it doesn't. I've read through the > documentation and it all appears that I am doing the correct thing, > but it just isn't working for me. I'm really hoping that someone can > point out the "obvious" error that I'm completely missing here. :) > > I'm trying to pull back a list of all my blogs along with all of the > associated comments for each blog. This is what I currently have: > > table definitions: (I left out the data, but it is in there, trust > me...) > --- > > CREATE TABLE `blogs` ( > `id` int(11) NOT NULL auto_increment, > `title` varchar(50) default NULL, > `text` text, > `post_date` datetime default NULL, > `active` int(1) default NULL, > `sort` int(11) default NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ; > > -- > -- Table structure for table `comments` > -- > > CREATE TABLE `comments` ( > `id` int(11) NOT NULL auto_increment, > `title` varchar(75) NOT NULL default '', > `text` text NOT NULL, > `date` date NOT NULL default '-00-00', > `author` varchar(100) NOT NULL default '', > `blog_id` int(11) NOT NULL default '0', > CONSTRAINT fk_comments_blog foreign key (blog_id) references > blogs(id), > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; > > --- > > comment.php > --- > > class Comment extends AppModel { > >var $name = 'Comment'; > >//The Associations below have been created with all possible keys, > those that are not needed can be removed >var $belongsTo = array( >'Blog' => >array('className' => 'Blog') > >); > > } > > --- > > blog.php > --- > > class Blog extends AppModel { > >var $name = 'Blog'; >var $hasMany = array('Comment' => > array('className'=>'Comment') >); > >var $validate = array( >'title' => VALID_NOT_EMPTY, >'text' => VALID_NOT_EMPTY, >'sort' => VALID_NUMBER, >); > } > > --- > > >From blogs_controller.php > --- > >function cp_index() { >$this->Blog->recursive = 0; > >$this->set('blogs', $this->Blog->findAll()); >$this->set('page_header', "Shoe Sole - List Blogs"); >$this->layout = 'list'; >} > > --- > > Now I would expect the $this->Blog->findAll() call to pull back an > array of blogs that has an array of comments within each respective > blog. However, this isn't the case. Instead it only pulls back blogs. > > And don't worry, I do actually have comments that are related to these > blogs, In fact, the $belongTo portion of the comments section works > perfectly and associates one blog to each comment exactly as I would > expect. > > So any help/guideance would be GREATLY appreciated. > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Help with a $hasMany, $belongsTo association...
Okay, I think this should work, but it doesn't. I've read through the documentation and it all appears that I am doing the correct thing, but it just isn't working for me. I'm really hoping that someone can point out the "obvious" error that I'm completely missing here. :) I'm trying to pull back a list of all my blogs along with all of the associated comments for each blog. This is what I currently have: table definitions: (I left out the data, but it is in there, trust me...) --- CREATE TABLE `blogs` ( `id` int(11) NOT NULL auto_increment, `title` varchar(50) default NULL, `text` text, `post_date` datetime default NULL, `active` int(1) default NULL, `sort` int(11) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ; -- -- Table structure for table `comments` -- CREATE TABLE `comments` ( `id` int(11) NOT NULL auto_increment, `title` varchar(75) NOT NULL default '', `text` text NOT NULL, `date` date NOT NULL default '-00-00', `author` varchar(100) NOT NULL default '', `blog_id` int(11) NOT NULL default '0', CONSTRAINT fk_comments_blog foreign key (blog_id) references blogs(id), PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; --- comment.php --- class Comment extends AppModel { var $name = 'Comment'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'Blog' => array('className' => 'Blog') ); } --- blog.php --- class Blog extends AppModel { var $name = 'Blog'; var $hasMany = array('Comment' => array('className'=>'Comment') ); var $validate = array( 'title' => VALID_NOT_EMPTY, 'text' => VALID_NOT_EMPTY, 'sort' => VALID_NUMBER, ); } --- >From blogs_controller.php --- function cp_index() { $this->Blog->recursive = 0; $this->set('blogs', $this->Blog->findAll()); $this->set('page_header', "Shoe Sole - List Blogs"); $this->layout = 'list'; } --- Now I would expect the $this->Blog->findAll() call to pull back an array of blogs that has an array of comments within each respective blog. However, this isn't the case. Instead it only pulls back blogs. And don't worry, I do actually have comments that are related to these blogs, In fact, the $belongTo portion of the comments section works perfectly and associates one blog to each comment exactly as I would expect. So any help/guideance would be GREATLY appreciated. --~--~-~--~~~---~--~~ 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: Multiple hasMany / belongsTo
Oh, those are specific to my application. The transaction table in my database has "from" and "to" fields to help keep track of which user is the receiver and which user is the sender. Barton wrote: > Interesting, but what I don't get are the classNames "From' and 'To'. > What do you do with it? Did you create for 'From' and 'To' a model? --~--~-~--~~~---~--~~ 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: Multiple hasMany / belongsTo
Interesting, but what I don't get are the classNames "From' and 'To'. What do you do with it? Did you create for 'From' and 'To' a model? --~--~-~--~~~---~--~~ 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: Multiple hasMany / belongsTo
A-ha! I have no idea what I was thinking :) Thanks! It seems to be working properly now. --~--~-~--~~~---~--~~ 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: Multiple hasMany / belongsTo
What am I doing wrong? Are my hasMany/belongsTo statements wrong? I get no errors. It looks correct to me too (but I'm also quite new to CakePHP ;) ). Did you enable SQL debug output (in app/config/core.php) ? Did it try to generate the SQL for the associations, or did it not even try that ? Anselm --~--~-~--~~~---~--~~ 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: Multiple hasMany / belongsTo
hi your hasMany, belongsTo, and all associations definitions will work better if they are in your Model classes rather than in your Controller classes ! ++ clemos On 1/15/07, squidliberty <[EMAIL PROTECTED]> wrote: Hi, I am still pretty new to CakePHP and I am having trouble doing something relatively simple... I have a database of members and I need to record transactions between members. At its most simple, each transaction entry needs an amount, a sender id and a receiver id. So my database looks something like this: Table 'members' - id Table 'transactions' - id - member_to - member_from - amount It is important to differentiate between the sending member and the receiving member. I am new to hasMany, but I surmise that my controllers should look something like this: class MembersController extends AppController { var $name = 'Members'; var $hasMany = array('Credit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_to', 'dependent' => false, 'exclusive' => false, 'finderQuery' => ''), 'Debit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_from', 'dependent' => false, 'exclusive' => false, 'finderQuery' => '')); } class TransactionsController extends AppController { var $name = 'Transactions'; var $scaffold; var $belongsTo = array('From' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_from'), 'To' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_to')); } So, although this makes sense to me, when I load a member (using $this->Member->findById) and print out the array (using print_r()), I only see the 'Member' array... no 'Debit' or 'Credit' arrays... What am I doing wrong? Are my hasMany/belongsTo statements wrong? I get no errors. 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 -~--~~~~--~~--~--~---
Multiple hasMany / belongsTo
Hi, I am still pretty new to CakePHP and I am having trouble doing something relatively simple... I have a database of members and I need to record transactions between members. At its most simple, each transaction entry needs an amount, a sender id and a receiver id. So my database looks something like this: Table 'members' - id Table 'transactions' - id - member_to - member_from - amount It is important to differentiate between the sending member and the receiving member. I am new to hasMany, but I surmise that my controllers should look something like this: class MembersController extends AppController { var $name = 'Members'; var $hasMany = array('Credit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_to', 'dependent' => false, 'exclusive' => false, 'finderQuery' => ''), 'Debit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_from', 'dependent' => false, 'exclusive' => false, 'finderQuery' => '')); } class TransactionsController extends AppController { var $name = 'Transactions'; var $scaffold; var $belongsTo = array('From' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_from'), 'To' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_to')); } So, although this makes sense to me, when I load a member (using $this->Member->findById) and print out the array (using print_r()), I only see the 'Member' array... no 'Debit' or 'Credit' arrays... What am I doing wrong? Are my hasMany/belongsTo statements wrong? I get no errors. 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: Model behavior (hasMany/belongsTo etc.)
class User extends AppModel { var $name = 'User'; var $hasMany = array( 'Message' =>array( 'className' => 'Message', 'conditions'=> 'User.id = Message.from_id', 'foreignKey'=> 'user_id' ) ); } From what I understand of the manual (though I may be wrong), the 'conditions' field should be used to add extra condtions but not the linking expression itself, which is generated by Cake. What's more, when running a query from 'Message' it will look at the relationship defined in 'Message' (the 'belongsTo' array) but not the one in 'User' -- so your 'condition' is ignored. I think you should remove this 'conditions'. To get the User records the primary key of which is equal to the 'from_id' in your Message, you should define the Message association this way : class Message extends AppModel { var $name = 'Message'; var $belongsTo = array('User' => array( 'className' => 'User', 'foreignKey' => 'from_id' ) ); } Then running $message = $this->Message->findAll('Message.user_id=1'); Should return the expected data. Note that you can create new associations on the fly (if you need different foreignKey) use bindModel/unbindModel (see the manual chapter about models). Anselm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Model behavior (hasMany/belongsTo etc.)
Hello everyone, I have a problem and I hope anyone of you can help me with that. Certainly I have read a lot of topics about hasMany and the likes, but so far I couldn't find the answer I need. Let me start by explaining what I want: For now I have 2 models: message.php and user.php [code] class Message extends AppModel { var $name = 'Message'; var $belongsTo = array('User' => array( 'className' => 'User', 'foreignKey' => 'user_id' ) ); /* AND */ class User extends AppModel { var $name = 'User'; var $hasMany = array( 'Message' =>array( 'className' => 'Message', 'conditions'=> 'User.id = Message.from_id', 'foreignKey'=> 'user_id' ) ); } [/code] Ok sofar for the models. The thing I want is to do a select on the messages table getting all the messages send to a certain id. For now with this setup it's possible. However.. I want to get the username who have sent the message. I tried to do it with a ordinary query on my db and that worked: [sql code] SELECT m.user_id, m.from_id, m.subject, m.content, u.username FROM users u, messages m WHERE u.id = m.from_id AND m.user_id = 1 [/sql code] outputs: user_id from_id subject content username 2 1subject contentsXYZ Which is the result that I want. Here's the controller code: [code] var $uses=array('Message','User'); function xyz() { $message = $this->Message->findAll('Message.user_id=1'); pr($message); } [/code] cake gives me back this: [array output snippet] [0] => Array ( [Message] => Array ( [id] => 3 [user_id] => 1 [from_id] => 2 [created] => 2007-01-14 13:53:53 [subject] => 2nd message from test to username [content] => bdfiugfigsdifgisudgfiudsf fljhfughofdhpgifhoghdfg sdfghfsoguhodhfgohfdohg sdlghfdouhgodfhgohdfohodf ) [User] => Array ( [id] => 1 [useremail] => [username] => username [userpassword] => # [userfirstname] => first [userlastname] => last [created] => now() [delete_date] => -00-00 00:00:00 [ip] => ) ) [/array output snippet] Which is not what I want. I want to get the username and the messages this 'from_id' sent. So my question.. how do I get cake to give me back the same output as the ordinary query? Hope anyone can help me with this. Thanks in advance! Greets Ed --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Try... SubArea hasMany Branch Company hasMany Branch Branch belongsTo SubArea (fk sub_area_id) Branch belongsTo Company (fk company_id) -- Andy W --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Jon, that's actually what i did.. perhaps the names of the tables aren't very explicit because i came up with the many branches/company later.. here's my structure i have three tables: subarea: subarea belongs to an area which belongs to a city.. but each branch will just belong to one subarea company: general info about the company branch: this table has a company_id and a subarea_id field and other details about the branch... what i'm trying to figure out is how to setup the relationship between them.. --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
You certainly could, that makes perfect sense. --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
> Also, (if I didn't make it clear), you'd probably want to have one > Venue per physical location, especially if you're logging all that > information, which could easily vary by location. could you not have: Company hasmany branches area hasMany branches then only the specifics of each branch would need changing, and there would be no need to add a new company for each branch ?? jb -- jon bennett t: +44 (0) 1225 341 039 w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Also, (if I didn't make it clear), you'd probably want to have one Venue per physical location, especially if you're logging all that information, which could easily vary by location. --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
My point about the hierarchy was to have a specific breakdown and clear separation between the areas. If there is no overlap between the Areas at the extremities of the tree, then each Venue could only belong to one Area. --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
On 4/6/06, zis <[EMAIL PROTECTED]> wrote: > Gustavo, > lol. you win the most perseverant reader award. Thanks !! Could you fax it to my inbox ? ;) -- < If you know Red Hat you know Red Hat, If you know Slackware you know Linux > --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Nate, actually, i do have a hierarchy.. i even have three levels: city, area, subarea The one level was to simplify things. But the reason i need to have each venue to be in multiple areas is for multiple branches.. as i said in my first post, there are many mcdonalds in one city.. so the venue mcdonalds is in many subareas... it get complicated when each branch of mcdonalds (every mcdonald in an area) has different properties i want to put in the database (if it offers takeaway, delivery, nonsmoking space, breakfast...) Gustavo, lol. you win the most perseverant reader award. --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Personally, I'd start by reorganizing your Areas into a tree hierarchy, i.e. have "Downtown" be the parent Area of "Business District". Then, just have each venue belong to one Area. --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
On 4/5/06, zis <[EMAIL PROTECTED]> wrote: > Oh.. and i didn't expect anyone to read the whole post.. i couldn't > even read it to check for mistakes ;) If there is a prize on reading the whole post, where do I claim it ? ;-) -- < If you know Red Hat you know Red Hat, If you know Slackware you know Linux > --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Thanks AD7six. Nate's reply is exactly the answer i was looking for.. i guess i must have tried searching.. Oh.. and i didn't expect anyone to read the whole post.. i couldn't even read it to check for mistakes ;) zis --~--~-~--~~~---~--~~ 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: hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Hi Zis, I have to admit that I didn't read your whole post ;o). If you need to add extra data to the link table, then it isn't 'just' a link table any more, and HABTM doesn´t describe the relationship (in a way that cake will automatically undertstand it, anyway). I think Nate's reply in this thread concisely addresses what you are looking for: http://groups.google.com/group/cake-php/browse_thread/thread/bef70558f7854732/6363603e04fcee68?lnk=st&q=&rnum=10#6363603e04fcee68 Hope it helps, cheers, AD7six Looking for CakePHP info? Find it faster here: http://www.cakephp.org/search/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasAndBelongsToMany vs hasMany & BelongsTo..... (long and boring)
Hi, I am currenlty building a directory with cake and have a fairly complex architecture. I'dd like to have your opinion for the best model setup. Here are two of my tables: venues: is the table who holds the list of venues and has the following fields: id, name, description areas: holds the list of different geographical areas.. and has the following fields: id, name for example, a venue could be McDonalds. and areas could be, downtown, old part, business district... Now, each venue could be in many areas (a McDonalds in downtown and business dist..).. but also each district can have many venues in it (there could be a mcdonalds and a Burger King in downtown). Anyone still following? the logical was of linking them is doing a link table with venue_id and area_id.. and put a $hasAndBelongsToMany in both venues and areas models. The problem is: the downtown mcdonalds could have a drive through but the business district doesnt.. or a non smoking area. .or offers breakfast.. or whatever.. the point is, each venue/area combination has unique settings.. to solve this i evolved the link table into a more elaborate one with the following fields: id, venue_id, area_id, smoking, parking, drivethrough... basically, the link ids and the option fields.. Now the tricky part (If someone is still following, WOW). I created a model and controller for the new table i called details. The question is, should the venues and areas models still have $hasAndBelongsToMany = ;details'? or should venues and areas should have a $hasMany = 'details' and the details model have $belongsTo areas and venues If anyone understood anything and has an answer... thanks.. really. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---