Re: Correct model associations
I sorted it out by using the HasMany thorough relation and by correcting the $data feed. On Friday, February 6, 2015 at 8:46:08 PM UTC, gt0p wrote: > > I am trying to bind 3 tables and I am having problems with proper > relations. > Table users (pk id), books (pk id), users_books (user_id, book_id), > comments (pk and foreign key book_id, user_id -> with reference to > users_books) > > Here are the models: > > Book > > public $hasAndBelongsToMany = array( > 'User' => > array( > 'className' => 'User', > 'joinTable' => 'users_books', > 'foreignKey' => 'book_id', > 'associationForeignKey' => 'user_id', > 'unique' => true, > 'conditions' => '', > 'fields' => '', > 'order' => '', > 'limit' => '', > 'offset' => '', > 'finderQuery' => '', > // 'with' => 'UserBook' > ),); > > public $hasMany = array('Comment'=>array('className'=>'Comment')); > > Comment: > > public $belongsTo = array ( > 'Book' => array ( > 'className'=>'Book', > > ) > ); > > > When I try to save with the saveAll method I got: > > *Error: * SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot > add or update a child row: a foreign key constraint fails > (`metabook`.`comments`, CONSTRAINT `comments_ibfk_1` FOREIGN KEY > (`user_id`, `book_id`) REFERENCES `users_books` (`user_id`, `book_id`)) > > I know that this is not according to the cakephp conventions, but what I > can do to bind those tables? > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Correct model associations
I already missed one valid model association - has many through, and that solved my issue. Thanks anyway for the reply! On Monday, February 9, 2015 at 5:25:58 PM UTC, John Andersen wrote: > > Assuming you are using CakePHP 2.x > > It is a good idea to define a primary key in your HABTM table - in the > books_users table (name should be alphabetic order, but you can deviate). > Thus your table definition is: > books_users > id, book_id, user_id > > What is your comment table reflecting? > 1) comments added to a book by a user? > 2) comments added to a book_user? > > To me it sounds like you have implemented 2) - if that is so, please > clarify your reason :) > > I would go with 1) - so that your comments table definition becomes: > comments > id, book_id, user_id, comment, ... > where book_id is a reference to the books table and user_id is a reference > to the users table. > > Enjoy, John > > > On Friday, 6 February 2015 22:46:08 UTC+2, gt0p wrote: >> >> I am trying to bind 3 tables and I am having problems with proper >> relations. >> Table users (pk id), books (pk id), users_books (user_id, book_id), >> comments (pk and foreign key book_id, user_id -> with reference to >> users_books) >> >> Here are the models: >> >> Book >> >> public $hasAndBelongsToMany = array( >> 'User' => >> array( >> 'className' => 'User', >> 'joinTable' => 'users_books', >> 'foreignKey' => 'book_id', >> 'associationForeignKey' => 'user_id', >> 'unique' => true, >> 'conditions' => '', >> 'fields' => '', >> 'order' => '', >> 'limit' => '', >> 'offset' => '', >> 'finderQuery' => '', >> // 'with' => 'UserBook' >> ),); >> >> public $hasMany = array('Comment'=>array('className'=>'Comment')); >> >> Comment: >> >> public $belongsTo = array ( >> 'Book' => array ( >> 'className'=>'Book', >> >> ) >> ); >> >> >> When I try to save with the saveAll method I got: >> >> *Error: * SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot >> add or update a child row: a foreign key constraint fails >> (`metabook`.`comments`, CONSTRAINT `comments_ibfk_1` FOREIGN KEY >> (`user_id`, `book_id`) REFERENCES `users_books` (`user_id`, `book_id`)) >> >> I know that this is not according to the cakephp conventions, but what I >> can do to bind those tables? >> > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Correct model associations
Assuming you are using CakePHP 2.x It is a good idea to define a primary key in your HABTM table - in the books_users table (name should be alphabetic order, but you can deviate). Thus your table definition is: books_users id, book_id, user_id What is your comment table reflecting? 1) comments added to a book by a user? 2) comments added to a book_user? To me it sounds like you have implemented 2) - if that is so, please clarify your reason :) I would go with 1) - so that your comments table definition becomes: comments id, book_id, user_id, comment, ... where book_id is a reference to the books table and user_id is a reference to the users table. Enjoy, John On Friday, 6 February 2015 22:46:08 UTC+2, gt0p wrote: > > I am trying to bind 3 tables and I am having problems with proper > relations. > Table users (pk id), books (pk id), users_books (user_id, book_id), > comments (pk and foreign key book_id, user_id -> with reference to > users_books) > > Here are the models: > > Book > > public $hasAndBelongsToMany = array( > 'User' => > array( > 'className' => 'User', > 'joinTable' => 'users_books', > 'foreignKey' => 'book_id', > 'associationForeignKey' => 'user_id', > 'unique' => true, > 'conditions' => '', > 'fields' => '', > 'order' => '', > 'limit' => '', > 'offset' => '', > 'finderQuery' => '', > // 'with' => 'UserBook' > ),); > > public $hasMany = array('Comment'=>array('className'=>'Comment')); > > Comment: > > public $belongsTo = array ( > 'Book' => array ( > 'className'=>'Book', > > ) > ); > > > When I try to save with the saveAll method I got: > > *Error: * SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot > add or update a child row: a foreign key constraint fails > (`metabook`.`comments`, CONSTRAINT `comments_ibfk_1` FOREIGN KEY > (`user_id`, `book_id`) REFERENCES `users_books` (`user_id`, `book_id`)) > > I know that this is not according to the cakephp conventions, but what I > can do to bind those tables? > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Correct model associations
I am trying to bind 3 tables and I am having problems with proper relations. Table users (pk id), books (pk id), users_books (user_id, book_id), comments (pk and foreign key book_id, user_id -> with reference to users_books) Here are the models: Book public $hasAndBelongsToMany = array( 'User' => array( 'className' => 'User', 'joinTable' => 'users_books', 'foreignKey' => 'book_id', 'associationForeignKey' => 'user_id', 'unique' => true, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'finderQuery' => '', // 'with' => 'UserBook' ),); public $hasMany = array('Comment'=>array('className'=>'Comment')); Comment: public $belongsTo = array ( 'Book' => array ( 'className'=>'Book', ) ); When I try to save with the saveAll method I got: *Error: * SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`metabook`.`comments`, CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`user_id`, `book_id`) REFERENCES `users_books` (`user_id`, `book_id`)) I know that this is not according to the cakephp conventions, but what I can do to bind those tables? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Bake and model associations
OK - just realised what the problem was. I restructured a legacy database in accordance with Cake conventions, but when I added the "child" columns, I simply appended "_id" to the parent table name, instead of "singularising" it, e.g. using "part_id" to reference parts.id. All now fine! -- View this message in context: http://cakephp.1045679.n5.nabble.com/Bake-and-model-associations-tp5717978p5717979.html Sent from the CakePHP mailing list archive at Nabble.com. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
RE: Help with Model associations and find
Hi Again, With your suggestion and Anja's suggestion of containable behaviour I have gotten this working. Thanks so much! HUGELY appreciated J Below is the code. All that was missing was to tell the Model to use containable behaviour: $this->DataImport->Behaviors->load('Containable'); return $this->DataImport->find( 'first', array( 'order' => array( 'created' => 'DESC' ), 'contain' => array( 'TelemetryData' => array( 'Hospital' => array( 'Province' ) ) ), 'recursive' => 3 ) ) ); From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of lowpass Sent: 06 September 2013 01:51 AM To: cake-php@googlegroups.com Subject: Re: Help with Model associations and find If I understand correctly, you want the latest DataImport record, and all of its associated ClientData records, each of which should include Hospital and Province. If that's correct, you should be calling find() on the DataImport model, which you can do because they're chained due to the association. Using Containable: $this->set('data', $this->ClientData->DataImport->getLatest()); DatImport model: public function getLatest() { return $this->find( 'first', array( 'order' => array( $this->alias.'.created' => 'DESC' ), 'contain' => array( 'ClientData' => array( 'Hospital' => array( 'Province' ) ) ) ) ); } We use 'order' but 'limit' is unnecessary, as it turns out, because of 'first'. At least, I'm pretty sure I discovered that one time. If you get strange results, try adding 'limit' => 1 atthe same level as the limit & contain arrays. On Wed, Sep 4, 2013 at 6:22 PM, Nikki McMahon wrote: Hi Anja, Thanks for replying. I actually want all ClientData with its related data. But, on the final level I only want the Province data and not the DataImport data, since DataImport is associated to ClientData and so then each DataImport holds all the ClientData associated to it as well. Something along these lines is what I get back now if I want to get Province data (I get it by setting recursive to a higher value) ClientData: ClientData[1]['id'] = 4; ClientData[1]['name'] = 'Client Name'; ClientData[1]['DataImport']['id'] = 10; ClientData[1]['DataImport']['ClientData'][1] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][2] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][3] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][4] = object;// excessive and unnecessary data ClientData[1]['Hospital']['id'] = 5; ClientData[1]['Hospital']['Province']['id'] = 9; ClientData[1]['Hospital']['Province']['name'] = 'Gauteng'; ClientData[2]['id'] = 6; ClientData[2]['name'] = 'Client Name 2'; ClientData[2]['DataImport']['id'] = 10; ClientData[2]['DataImport']['ClientData'][1] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][2] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][3] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][4] = object;// excessive and unnecessary data ClientData[2]['Hospital']['id'] = 8; ClientData[2]['Hospital']['Province']['id'
RE: Help with Model associations and find
Hi there, Thanks for this. I tried it out and what I got was a list of ClientData with the DataImport, but none of the other data. So I set recursive to 3 and I still get back DataImport (under ClientData) with all of the ClientData under that. I see the 'contain' field. Is there a way to stop it containing something on the nth level of recursion? My data suggests that the contain is not working properly. $this->DataImport->find( 'first', array( 'order' => array( $this->alias.'created' => 'DESC' ), 'contain' => array( 'TelemetryData' => array( 'Hospital' => array( 'Province' ) ) ), 'recursive' => 3 ) ) Thanks for the help! From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of lowpass Sent: 06 September 2013 01:51 AM To: cake-php@googlegroups.com Subject: Re: Help with Model associations and find If I understand correctly, you want the latest DataImport record, and all of its associated ClientData records, each of which should include Hospital and Province. If that's correct, you should be calling find() on the DataImport model, which you can do because they're chained due to the association. Using Containable: $this->set('data', $this->ClientData->DataImport->getLatest()); DatImport model: public function getLatest() { return $this->find( 'first', array( 'order' => array( $this->alias.'.created' => 'DESC' ), 'contain' => array( 'ClientData' => array( 'Hospital' => array( 'Province' ) ) ) ) ); } We use 'order' but 'limit' is unnecessary, as it turns out, because of 'first'. At least, I'm pretty sure I discovered that one time. If you get strange results, try adding 'limit' => 1 atthe same level as the limit & contain arrays. On Wed, Sep 4, 2013 at 6:22 PM, Nikki McMahon wrote: Hi Anja, Thanks for replying. I actually want all ClientData with its related data. But, on the final level I only want the Province data and not the DataImport data, since DataImport is associated to ClientData and so then each DataImport holds all the ClientData associated to it as well. Something along these lines is what I get back now if I want to get Province data (I get it by setting recursive to a higher value) ClientData: ClientData[1]['id'] = 4; ClientData[1]['name'] = 'Client Name'; ClientData[1]['DataImport']['id'] = 10; ClientData[1]['DataImport']['ClientData'][1] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][2] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][3] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][4] = object;// excessive and unnecessary data ClientData[1]['Hospital']['id'] = 5; ClientData[1]['Hospital']['Province']['id'] = 9; ClientData[1]['Hospital']['Province']['name'] = 'Gauteng'; ClientData[2]['id'] = 6; ClientData[2]['name'] = 'Client Name 2'; ClientData[2]['DataImport']['id'] = 10; ClientData[2]['DataImport']['ClientData'][1] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][2] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][3] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][4] = object;// excessive and unnecessary data ClientData[2]['Hospital']['id'] = 8; ClientData[2]['Hospital']['Province']['id'] = 4; ClientData[2]['Hospital']['Province']['name'] = 'Eastern Cape'; This is what I would like it to look like - excessive ClientData removed. Because of the level of recursion, the DataImport object loops back in on itself, where the Hospital object expands to its logical end. ClientData[1]['id'] = 4; Client
Re: Help with Model associations and find
If I understand correctly, you want the latest DataImport record, and all of its associated ClientData records, each of which should include Hospital and Province. If that's correct, you should be calling find() on the DataImport model, which you can do because they're chained due to the association. Using Containable: $this->set('data', $this->ClientData->DataImport->getLatest()); DatImport model: public function getLatest() { return $this->find( 'first', array( 'order' => array( $this->alias.'.created' => 'DESC' ), 'contain' => array( 'ClientData' => array( 'Hospital' => array( 'Province' ) ) ) ) ); } We use 'order' but 'limit' is unnecessary, as it turns out, because of 'first'. At least, I'm pretty sure I discovered that one time. If you get strange results, try adding 'limit' => 1 atthe same level as the limit & contain arrays. On Wed, Sep 4, 2013 at 6:22 PM, Nikki McMahon wrote: > Hi Anja, > > Thanks for replying. > > I actually want all ClientData with its related data. But, on the final > level I only want the Province data and not the DataImport data, since > DataImport is associated to ClientData and so then each DataImport holds > all > the ClientData associated to it as well. > > Something along these lines is what I get back now if I want to get > Province > data (I get it by setting recursive to a higher value) > > ClientData: > ClientData[1]['id'] = 4; > ClientData[1]['name'] = 'Client Name'; > ClientData[1]['DataImport']['id'] = 10; > ClientData[1]['DataImport']['ClientData'][1] = object;// excessive and > unnecessary data > ClientData[1]['DataImport']['ClientData'][2] = object;// excessive and > unnecessary data > ClientData[1]['DataImport']['ClientData'][3] = object;// excessive and > unnecessary data > ClientData[1]['DataImport']['ClientData'][4] = object;// excessive and > unnecessary data > ClientData[1]['Hospital']['id'] = 5; > ClientData[1]['Hospital']['Province']['id'] = 9; > ClientData[1]['Hospital']['Province']['name'] = 'Gauteng'; > ClientData[2]['id'] = 6; > ClientData[2]['name'] = 'Client Name 2'; > ClientData[2]['DataImport']['id'] = 10; > ClientData[2]['DataImport']['ClientData'][1] = object;// excessive and > unnecessary data > ClientData[2]['DataImport']['ClientData'][2] = object;// excessive and > unnecessary data > ClientData[2]['DataImport']['ClientData'][3] = object;// excessive and > unnecessary data > ClientData[2]['DataImport']['ClientData'][4] = object;// excessive and > unnecessary data > ClientData[2]['Hospital']['id'] = 8; > ClientData[2]['Hospital']['Province']['id'] = 4; > ClientData[2]['Hospital']['Province']['name'] = 'Eastern Cape'; > > This is what I would like it to look like - excessive ClientData removed. > Because of the level of recursion, the DataImport object loops back in on > itself, where the Hospital object expands to its logical end. > > ClientData[1]['id'] = 4; > ClientData[1]['name'] = 'Client Name'; > ClientData[1]['DataImport']['id'] = 10; > ClientData[1]['Hospital']['id'] = 5; > ClientData[1]['Hospital']['Province']['id'] = 9; > ClientData[1]['Hospital']['Province']['name'] = 'Gauteng'; > ClientData[2]['id'] = 6; > ClientData[2]['name'] = 'Client Name 2'; > ClientData[2]['DataImport']['id'] = 10; > ClientData[2]['Hospital']['id'] = 8; > ClientData[2]['Hospital']['Province']['id'] = 4; > ClientData[2]['Hospital']['Province']['name'] = 'Eastern Cape'; > > I'm not sure if this helps at all? > I basically loop through ClientData after pulling this, adjust some values > according to algorithms and then print it out into a table. In that table I > need to print the Province name, which is why I need to pull the province. > > I am beginning to think I might just do the ugly thing and import the > hospital model and pull the name in the loop. Time constraints are a big > issue on this project. > > Thanks again for replying, > Nik
RE: Help with Model associations and find
Hi Anja, Thanks for replying. I actually want all ClientData with its related data. But, on the final level I only want the Province data and not the DataImport data, since DataImport is associated to ClientData and so then each DataImport holds all the ClientData associated to it as well. Something along these lines is what I get back now if I want to get Province data (I get it by setting recursive to a higher value) ClientData: ClientData[1]['id'] = 4; ClientData[1]['name'] = 'Client Name'; ClientData[1]['DataImport']['id'] = 10; ClientData[1]['DataImport']['ClientData'][1] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][2] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][3] = object;// excessive and unnecessary data ClientData[1]['DataImport']['ClientData'][4] = object;// excessive and unnecessary data ClientData[1]['Hospital']['id'] = 5; ClientData[1]['Hospital']['Province']['id'] = 9; ClientData[1]['Hospital']['Province']['name'] = 'Gauteng'; ClientData[2]['id'] = 6; ClientData[2]['name'] = 'Client Name 2'; ClientData[2]['DataImport']['id'] = 10; ClientData[2]['DataImport']['ClientData'][1] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][2] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][3] = object;// excessive and unnecessary data ClientData[2]['DataImport']['ClientData'][4] = object;// excessive and unnecessary data ClientData[2]['Hospital']['id'] = 8; ClientData[2]['Hospital']['Province']['id'] = 4; ClientData[2]['Hospital']['Province']['name'] = 'Eastern Cape'; This is what I would like it to look like - excessive ClientData removed. Because of the level of recursion, the DataImport object loops back in on itself, where the Hospital object expands to its logical end. ClientData[1]['id'] = 4; ClientData[1]['name'] = 'Client Name'; ClientData[1]['DataImport']['id'] = 10; ClientData[1]['Hospital']['id'] = 5; ClientData[1]['Hospital']['Province']['id'] = 9; ClientData[1]['Hospital']['Province']['name'] = 'Gauteng'; ClientData[2]['id'] = 6; ClientData[2]['name'] = 'Client Name 2'; ClientData[2]['DataImport']['id'] = 10; ClientData[2]['Hospital']['id'] = 8; ClientData[2]['Hospital']['Province']['id'] = 4; ClientData[2]['Hospital']['Province']['name'] = 'Eastern Cape'; I'm not sure if this helps at all? I basically loop through ClientData after pulling this, adjust some values according to algorithms and then print it out into a table. In that table I need to print the Province name, which is why I need to pull the province. I am beginning to think I might just do the ugly thing and import the hospital model and pull the name in the loop. Time constraints are a big issue on this project. Thanks again for replying, Nikki -Original Message- From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of Anja Liebermann Sent: 04 September 2013 07:44 PM To: cake-php@googlegroups.com Subject: Re: Help with Model associations and find -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Nikki, if I undestand it correctly this might be a case for the Containable behaviour. But I am not sure what your fields information will do. What do you get back, if you leave that out? Is it correct, that you want to have all your clientData but not the complete range of connected data? Anja Am 03.09.2013 22:14, schrieb Nif: > Hi All, > > I have something I am struggling with and hoping someone can help? > I've used Cake for some simple tools and site structure in the past > and I'm currently working on my first complex db design within the framework. > > I know how to do this in mySQL, but cannot figure out how to use > Cake's Model associations and find method to get it done. - All > associations are set up in the Models already. > > I have a table 'ClientData'. It has foreign keys to 2 other tables, > Hospital and DataImport. This is a manyToOne relationship (I think - > basically, many ClientData's can have one Hospital and DataImport). > Hospital then has a foreign key to the Province table (Many Hospitals > can have one Province). >
Re: Help with Model associations and find
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Nikki, if I undestand it correctly this might be a case for the Containable behaviour. But I am not sure what your fields information will do. What do you get back, if you leave that out? Is it correct, that you want to have all your clientData but not the complete range of connected data? Anja Am 03.09.2013 22:14, schrieb Nif: > Hi All, > > I have something I am struggling with and hoping someone can help? I've > used Cake for some simple tools and site structure in the past and I'm > currently working on my first complex db design within the framework. > > I know how to do this in mySQL, but cannot figure out how to use Cake's > Model associations and find method to get it done. - All associations are > set up in the Models already. > > I have a table 'ClientData'. It has foreign keys to 2 other tables, > Hospital and DataImport. This is a manyToOne relationship (I think - > basically, many ClientData's can have one Hospital and DataImport). > Hospital then has a foreign key to the Province table (Many Hospitals can > have one Province). > > so: > [1]['id'] = 4; > [1]['name'] = 'Client Name'; > [1]['DataImport']['id'] = 10; > [1]['Hospital']['id'] = 5; > [1]['Hospital']['Province']['id'] = 9; > > That's the basic layout (minus lots of the actual data) where [i] is the > ClientData row and the result will have many ClientData rows. > > I want to select all of the ClientData's that are associated to the latest > created DataImport and get back The ClientData with the Hospital data > associated to the ClientData and then subsequently the Province data > associated to the Hospital - Much like the structure above. > > I am using this code: > $latestData = $this->ClientData->find('all',array('fields'=>array('MAX(Dat > aImport.created)','*'),'recursive' => 1)); > But all I receive is one ClientData row and the MAX created field. If I > increase recursive to 3 then I get 1 ClientData row with associated data > alongside (Hospital and DataImport) and then inside the DataImport row are > all the ClientDatas I want and under those are DataImport data and Hospital > Data. > > This is part of the way correct, however, I don't feel it is right... seems > odd to have that top level return of one ClientData and it's associations > and then have the rest under the DataImport associated to that one > ClientData, all with their own DataImport data. > > Also, I still don't have the Province data I want. If I increase recursive > to 4 then I get teh hospital data but also the very sub level DataImport > under each ClientData brings back all the ClientData once again. > > I am sure there must be a better way to do this, but I just cannot find out > how. > I can import the Hospital Model and then create a function to pull it's > data which will bring the Province data associated, but this just isn't > good practice and I really want to use the Model associations properly. > > Sorry, I know this is long winded and possibly not well described. I hope > it makes sense. > Any advice or help would be very much appreciated. > Thanks in advance, > Nikki > -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlIncUoACgkQbOdiIJzHNKHS/wCfbkLt10XB7WclFcLuHQo78N2n 21EAn1AIVhWr1Vd9BuAgyZi1vPa82ya4 =UQ/b -END PGP SIGNATURE- -- 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.
Help with Model associations and find
Hi All, I have something I am struggling with and hoping someone can help? I've used Cake for some simple tools and site structure in the past and I'm currently working on my first complex db design within the framework. I know how to do this in mySQL, but cannot figure out how to use Cake's Model associations and find method to get it done. - All associations are set up in the Models already. I have a table 'ClientData'. It has foreign keys to 2 other tables, Hospital and DataImport. This is a manyToOne relationship (I think - basically, many ClientData's can have one Hospital and DataImport). Hospital then has a foreign key to the Province table (Many Hospitals can have one Province). so: [1]['id'] = 4; [1]['name'] = 'Client Name'; [1]['DataImport']['id'] = 10; [1]['Hospital']['id'] = 5; [1]['Hospital']['Province']['id'] = 9; That's the basic layout (minus lots of the actual data) where [i] is the ClientData row and the result will have many ClientData rows. I want to select all of the ClientData's that are associated to the latest created DataImport and get back The ClientData with the Hospital data associated to the ClientData and then subsequently the Province data associated to the Hospital - Much like the structure above. I am using this code: $latestData = $this->ClientData->find('all',array('fields'=>array('MAX(Dat aImport.created)','*'),'recursive' => 1)); But all I receive is one ClientData row and the MAX created field. If I increase recursive to 3 then I get 1 ClientData row with associated data alongside (Hospital and DataImport) and then inside the DataImport row are all the ClientDatas I want and under those are DataImport data and Hospital Data. This is part of the way correct, however, I don't feel it is right... seems odd to have that top level return of one ClientData and it's associations and then have the rest under the DataImport associated to that one ClientData, all with their own DataImport data. Also, I still don't have the Province data I want. If I increase recursive to 4 then I get teh hospital data but also the very sub level DataImport under each ClientData brings back all the ClientData once again. I am sure there must be a better way to do this, but I just cannot find out how. I can import the Hospital Model and then create a function to pull it's data which will bring the Province data associated, but this just isn't good practice and I really want to use the Model associations properly. Sorry, I know this is long winded and possibly not well described. I hope it makes sense. Any advice or help would be very much appreciated. Thanks in advance, Nikki -- 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: Form helper not adding "required" class to fields from deep model associations
Anyone? :) On Fri, May 17, 2013 at 4:04 PM, Alex Bovey wrote: > Hi all, > > In my Cake 2.3 app I'm using saveAll($this->request->data, array('deep' => > true)) to save deep model associations and the validation is working fine. > My input fields for any deeply associated models have the error class > applied if I try to submit the form having left them blank, which is great. > > The problem is that the Form helper isn't adding the "required" class to > the div of any deeply associated models - e.g.: > > - > > echo $this->Form->create('MyModel'); > echo $this->Form->input('MyModel.required_field); // this field correctly > has the "required" class :-) > echo $this->Form->input('MyRelatedModel.required_field); // this field > also has the "required" class :-) > echo $this->Form->input('MyRelatedModel.AnotherModel.required_field); // > this field does NOT have the "required" class :-( > > - > > Does anyone know of a solution? > > Thanks! > > Alex > > -- 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.
Form helper not adding "required" class to fields from deep model associations
Hi all, In my Cake 2.3 app I'm using saveAll($this->request->data, array('deep' => true)) to save deep model associations and the validation is working fine. My input fields for any deeply associated models have the error class applied if I try to submit the form having left them blank, which is great. The problem is that the Form helper isn't adding the "required" class to the div of any deeply associated models - e.g.: - echo $this->Form->create('MyModel'); echo $this->Form->input('MyModel.required_field); // this field correctly has the "required" class :-) echo $this->Form->input('MyRelatedModel.required_field); // this field also has the "required" class :-) echo $this->Form->input('MyRelatedModel.AnotherModel.required_field); // this field does NOT have the "required" class :-( - Does anyone know of a solution? Thanks! Alex -- Alex Bovey Web Developer | Alex Bovey Consultancy Ltd Registered in England & Wales no. 6471391 | VAT no. 934 8959 65 a...@bovey.co.uk | t 0844 567 8995 | m 07828 649386 | f 0870 288 9533 PHP | CakePHP | MySQL | jQuery | HTML5 | CSS3 | Drupal | Wordpress | Hosting -- 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: Trouble with model associations and query.
I seem to have resolved this, but I don't think it's the most efficient query: public function getStudents(){ $userId = $this->Auth->user('id'); $endusers = $this->RoleUser->findAllByuser_id($userId, array('RoleUser.enduserid','RoleUser.user_id')); //Get the enduserid's for all the roles I have been assigned foreach ($endusers as $enduser){ $theusers[] = $this->User->findById($enduser['RoleUser']['enduserid']); //store each user to an array. } debug($theusers); Any ideas how I can get the same result by just querying the Users table and associated roles/userroles ? } On Sunday, December 9, 2012 2:30:38 PM UTC-5, MDay wrote: > > I am having trouble returning a query. I have the following setup > > Users - users class of all users in the system. > Roles - roles class with a set of available roles. E.g. teacher, student, > tutor > RoleUsers - a mapping table between users and roles as a single user can > have multiple roles. > > > My Users class has this > > public $hasAndBelongsToMany = array( > > 'Role' => > > array( > > 'className' => 'Role', > > 'joinTable' => 'role_users', //was > roles_users > > 'foreignKey' => 'user_id', > > 'associationForeignKey' => 'role_id', > > 'unique' => true) > > ); > > > My RolesUser class has this > > public $belongsTo = array( > > 'User' => > > array( > > 'className' => 'User', > > 'joinTable' => 'users', > > 'foreignKey' => 'user_id', > > 'unique' => true), > > 'Role' => > > array( > > 'className' => 'Role', > > 'joinTable' => 'roles', > > 'foreignKey' => 'role_id', > > 'unique' => true) > > > I am now trying to query the user table to determine the students > belonging to the logged in user (a teacher or tutor) > > > public function getStudents(){ > > $userId = $this->Auth->user('id'); > > $conditions = array('conditions' => array (array('Role.id =' => 75), //75 > is the role for all students > > array ('RoleUser.id = ' => $userId))); //this is the current logged in > user > > $result = $this->User->find('all',$conditions); > > debug($result); > > > In the top of my UsersController, I have: > > public $uses = array('Role', 'RoleUser'); > > > When I run the function getStudents above, I am getting *Error: *Call to > a member function find() on a non-object > > > ); > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: Trouble with model associations and query.
On Sun, Dec 9, 2012 at 2:30 PM, Md wrote: > > array ('RoleUser.id = ' => $userId))); //this is the current logged in user RolesUser -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Trouble with model associations and query.
I am having trouble returning a query. I have the following setup Users - users class of all users in the system. Roles - roles class with a set of available roles. E.g. teacher, student, tutor RoleUsers - a mapping table between users and roles as a single user can have multiple roles. My Users class has this public $hasAndBelongsToMany = array( 'Role' => array( 'className' => 'Role', 'joinTable' => 'role_users', //was roles_users 'foreignKey' => 'user_id', 'associationForeignKey' => 'role_id', 'unique' => true) ); My RolesUser class has this public $belongsTo = array( 'User' => array( 'className' => 'User', 'joinTable' => 'users', 'foreignKey' => 'user_id', 'unique' => true), 'Role' => array( 'className' => 'Role', 'joinTable' => 'roles', 'foreignKey' => 'role_id', 'unique' => true) I am now trying to query the user table to determine the students belonging to the logged in user (a teacher or tutor) public function getStudents(){ $userId = $this->Auth->user('id'); $conditions = array('conditions' => array (array('Role.id =' => 75), //75 is the role for all students array ('RoleUser.id = ' => $userId))); //this is the current logged in user $result = $this->User->find('all',$conditions); debug($result); In the top of my UsersController, I have: public $uses = array('Role', 'RoleUser'); When I run the function getStudents above, I am getting *Error: *Call to a member function find() on a non-object ); -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Scaffolded Form Input for Model Associations
After linking two models together with, for instance, using the $hasMany and $belongsTo definitions should I expect to see either a multi-select form input element in the add and edit scaffolded views for the model with the $hasMany definition? I would expect to get something in there but I don't see anything, does that mean something is wrong with my associations? Is this feature supported in Cake 2.2.3? Thanks in advance for any help, I've been wrestling with this for quite some time. Best, Shawn -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
New video tutorial: CakePHP basics part 4 - Model Associations
Hi cake lovers, I've just uploaded part 4 of my cakePHP basics tutorial series. In this one I'll explain how you can create associations in your models to get associated data from other models when you retrieve data. http://blog.the-nerd.be/2012/08/cakephp-basics-tutorial-part-4/ Hope you like it! Cheers, Frederik -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Model associations
cricket, thanks for the answear, but it´s not exactly this... I have a menu wich is generated dinamically in ALL pages of the site, so it´s a part of the layout and the categories information needs to be in all pages. Em sexta-feira, 10 de agosto de 2012 00h23min04s UTC-3, cricket escreveu: > > I'm not sure I follow all of that but I think what you want is a list > of all Categories for the main page, and all Products for a given > Category. If that's the case, I would set the main page as > CategoryController::index(). This is from one of my projects: > > Router::connect( > '/catalog', > array( > 'controller' => Categories', > 'action' => 'index' > ) > ); > Router::connect( > '/catalog/:slug', > array( > 'controller' => Categories', > 'action' => 'view' > ), > array( > 'slug' => '[-a-z0-9]+', > 'pass' => array('slug') > ) > ); > > Next, fetch the Category list directly from that model: > > public function index() > { > $this->set( > 'data', > $this->Category->find( > 'all', > array( > 'order' => array( > 'Category.name' => 'ASC' > ), > 'recursive' => -1 > ) > ) > ); > } > > public function view($slug = null) > { > if (empty($slug)) > { > ... > } > > $this->set( > 'data' > $this->Category->fetch($slug) > ); > } > > > Category model: > > public function fetch($slug) > { > return $this->find( > 'first', > array( > 'conditions' => array( > $this->alias.'.slug' => $slug > ), > 'contain' => array( > 'Product' > ) > ) > ); > } > > > On Thu, Aug 9, 2012 at 10:43 AM, André Luis > > wrote: > > Hi people, it´s me again! > > > > I am using a habtm relationship in my application, it works 100% fine... > But > > the Product menu is created dinamically with it´s Categories... so i > have > > Product model and the Category model with habtm relationship between > them. > > > > In AppController i have to set at beforeFilter the variable > > "products_categories", as i dont need the products of each category > right > > now i use > > > $this->set('products_categories",$this->Product->CatProduct->find('all')); > > and it works fine... BUT, latter when i need to read the product > category > > with it´s products, i would use $this->CatProduct->read('*',$id); right? > BUT > > it´s returning ONLY the category, not the products relateds, but if i > > comment the line $this->Product->CatProduct->find('all') it works fine, > and > > returns me the category and all related products. > > > > What i am doing wrong? Isnt there anyway to get only the categories them > get > > one category with it´s relateds? > > > > Thanks! > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "CakePHP" group. > > To post to this group, send email to cake...@googlegroups.com. > > > To unsubscribe from this group, send email to > > cake-php+u...@googlegroups.com . > > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. > > > > > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Model associations
Yes i do... I resolved the problem using requestAction, but i know that´s not correct. Em quinta-feira, 9 de agosto de 2012 17h28min29s UTC-3, Mark Wratten escreveu: > > Do you have var $belongsTo = array('Category', 'Product'); in your > CatProduct model? > > On Thursday, August 9, 2012 10:43:43 AM UTC-4, André Luis wrote: >> >> Hi people, it´s me again! >> >> I am using a habtm relationship in my application, it works 100% fine... >> But the Product menu is created dinamically with it´s Categories... so i >> have Product model and the Category model with habtm relationship between >> them. >> >> In AppController i have to set at beforeFilter the variable >> "products_categories", as i dont need the products of each category right >> now i use >> $this->set('products_categories",$this->Product->CatProduct->find('all')); >> and it works fine... BUT, latter when i need to read the product category >> with it´s products, i would use $this->CatProduct->read('*',$id); right? >> BUT it´s returning ONLY the category, not the products relateds, but if i >> comment the line $this->Product->CatProduct->find('all') it works fine, and >> returns me the category and all related products. >> >> What i am doing wrong? Isnt there anyway to get only the categories them >> get one category with it´s relateds? >> >> Thanks! >> > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Model associations
I'm not sure I follow all of that but I think what you want is a list of all Categories for the main page, and all Products for a given Category. If that's the case, I would set the main page as CategoryController::index(). This is from one of my projects: Router::connect( '/catalog', array( 'controller' => Categories', 'action' => 'index' ) ); Router::connect( '/catalog/:slug', array( 'controller' => Categories', 'action' => 'view' ), array( 'slug' => '[-a-z0-9]+', 'pass' => array('slug') ) ); Next, fetch the Category list directly from that model: public function index() { $this->set( 'data', $this->Category->find( 'all', array( 'order' => array( 'Category.name' => 'ASC' ), 'recursive' => -1 ) ) ); } public function view($slug = null) { if (empty($slug)) { ... } $this->set( 'data' $this->Category->fetch($slug) ); } Category model: public function fetch($slug) { return $this->find( 'first', array( 'conditions' => array( $this->alias.'.slug' => $slug ), 'contain' => array( 'Product' ) ) ); } On Thu, Aug 9, 2012 at 10:43 AM, André Luis wrote: > Hi people, it´s me again! > > I am using a habtm relationship in my application, it works 100% fine... But > the Product menu is created dinamically with it´s Categories... so i have > Product model and the Category model with habtm relationship between them. > > In AppController i have to set at beforeFilter the variable > "products_categories", as i dont need the products of each category right > now i use > $this->set('products_categories",$this->Product->CatProduct->find('all')); > and it works fine... BUT, latter when i need to read the product category > with it´s products, i would use $this->CatProduct->read('*',$id); right? BUT > it´s returning ONLY the category, not the products relateds, but if i > comment the line $this->Product->CatProduct->find('all') it works fine, and > returns me the category and all related products. > > What i am doing wrong? Isnt there anyway to get only the categories them get > one category with it´s relateds? > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com. > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. > > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Model associations
Do you have var $belongsTo = array('Category', 'Product'); in your CatProduct model? On Thursday, August 9, 2012 10:43:43 AM UTC-4, André Luis wrote: > > Hi people, it´s me again! > > I am using a habtm relationship in my application, it works 100% fine... > But the Product menu is created dinamically with it´s Categories... so i > have Product model and the Category model with habtm relationship between > them. > > In AppController i have to set at beforeFilter the variable > "products_categories", as i dont need the products of each category right > now i use > $this->set('products_categories",$this->Product->CatProduct->find('all')); > and it works fine... BUT, latter when i need to read the product category > with it´s products, i would use $this->CatProduct->read('*',$id); right? > BUT it´s returning ONLY the category, not the products relateds, but if i > comment the line $this->Product->CatProduct->find('all') it works fine, and > returns me the category and all related products. > > What i am doing wrong? Isnt there anyway to get only the categories them > get one category with it´s relateds? > > Thanks! > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Model associations
I´ve noticed that if i try do use the CatProduct in AppModel, the Product model becomes a AppModel object, and not a Product object anymore =( -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Model associations
Now when i try to use the find all in appcontroller it seems to remove my behaviors for latter uses, what i am doing wrong?? -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Model associations
Hi people, it´s me again! I am using a habtm relationship in my application, it works 100% fine... But the Product menu is created dinamically with it´s Categories... so i have Product model and the Category model with habtm relationship between them. In AppController i have to set at beforeFilter the variable "products_categories", as i dont need the products of each category right now i use $this->set('products_categories",$this->Product->CatProduct->find('all')); and it works fine... BUT, latter when i need to read the product category with it´s products, i would use $this->CatProduct->read('*',$id); right? BUT it´s returning ONLY the category, not the products relateds, but if i comment the line $this->Product->CatProduct->find('all') it works fine, and returns me the category and all related products. What i am doing wrong? Isnt there anyway to get only the categories them get one category with it´s relateds? Thanks! -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Model Associations Question
In you code you have 'className' => 'Bookings'. Shouldn't that be 'className' = 'Booking' ? You should also be able to shorten it to - var $belongsTo = array('Booking') as you are using booking_id as your foreign key. MArk On Wednesday, June 27, 2012 2:34:25 AM UTC-4, Sanfly wrote: > > Sorry, I'll repost this - my database is Bookingdate not Bookingnight > > Hi > > Im having some trouble with a model association - yes, I have tried the > manual! > > For each Booking I have, I can have many Bookingnights > > *Booking* > Booking.id > > > *Bookingdate* > Bookingdate.id > Bookingdate.booking_id > > In my Booking model, I am able to get all the associated Bookingdates > without issue. > > var $hasMany = array( > 'Bookingdate' => array( > 'className' => 'Bookingdates', > 'foreignKey'=> 'booking_id', > > ) > > ); > > My problem is when I try and go back the other way. I have my > Bookingdate.id, and want to get the associated booking. > > I would think that it should be belongsTo in my Bookingdate model? > > var $belongsTo = array( > 'Booking' => array( > 'className' => 'Bookings', > 'foreignKey' => 'booking_id' > ) > > ); > > ==> Doesnt Work > > Is there something obvious that I'm missing? > > On Wednesday, 27 June 2012 18:26:42 UTC+12, Sanfly wrote: >> >> Hi >> >> Im having some trouble with a model association - yes, I have tried the >> manual! >> >> For each Booking I have, I can have many Bookingnights >> >> *Booking* >> Booking.id >> >> >> *Bookingnight* >> Bookingnight.id >> Bookingnight.booking_id >> >> In my Booking model, I am able to get all the associated Bookingnights >> without issue. >> >> var $hasMany = array( >> 'Bookingdate' => array( >> 'className' => 'Bookingdates', >> 'foreignKey'=> 'booking_id', >> >> ) >> >> ); >> >> My problem is when I try and go back the other way. I have my >> Bookingnight.id, and want to get the associated booking. >> >> I would think that it should be belongsTo? >> >> var $belongsTo = array( >> 'Booking' => array( >> 'className' => 'Bookings', >> 'foreignKey' => 'booking_id' >> ) >> >> ); >> >> ==> Doesnt Work >> >> Is there something obvious that I'm missing? >> >> Thanks! >> >> >> >> -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations Question
This seems more like an HABTM association. A Booking can have/belong to many BookingDate and vice versa. I wonder, though, if it might be better to drop the BookingDate model and instead use date ranges. Something like date_from & date_to, or arrival & departure, in the bookings table. On Wed, Jun 27, 2012 at 2:34 AM, Sanfly wrote: > Sorry, I'll repost this - my database is Bookingdate not Bookingnight > > > Hi > > Im having some trouble with a model association - yes, I have tried the > manual! > > For each Booking I have, I can have many Bookingnights > > Booking > Booking.id > > > Bookingdate > Bookingdate.id > Bookingdate.booking_id > > In my Booking model, I am able to get all the associated Bookingdates > without issue. > > > var $hasMany = array( > 'Bookingdate' => array( > 'className' => 'Bookingdates', > 'foreignKey' => 'booking_id', > > ) > > ); > > My problem is when I try and go back the other way. I have my > Bookingdate.id, and want to get the associated booking. > > I would think that it should be belongsTo in my Bookingdate model? > > > var $belongsTo = array( > 'Booking' => array( > 'className' => 'Bookings', > 'foreignKey' => 'booking_id' > ) > > ); > > ==> Doesnt Work > > Is there something obvious that I'm missing? > > On Wednesday, 27 June 2012 18:26:42 UTC+12, Sanfly wrote: >> >> Hi >> >> Im having some trouble with a model association - yes, I have tried the >> manual! >> >> For each Booking I have, I can have many Bookingnights >> >> Booking >> Booking.id >> >> >> Bookingnight >> Bookingnight.id >> Bookingnight.booking_id >> >> In my Booking model, I am able to get all the associated Bookingnights >> without issue. >> >> var $hasMany = array( >> 'Bookingdate' => array( >> 'className' => 'Bookingdates', >> 'foreignKey' => 'booking_id', >> >> ) >> >> ); >> >> My problem is when I try and go back the other way. I have my >> Bookingnight.id, and want to get the associated booking. >> >> I would think that it should be belongsTo? >> >> var $belongsTo = array( >> 'Booking' => array( >> 'className' => 'Bookings', >> 'foreignKey' => 'booking_id' >> ) >> >> ); >> >> ==> Doesnt Work >> >> Is there something obvious that I'm missing? >> >> Thanks! >> >> >> > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations Question
Sorry, I'll repost this - my database is Bookingdate not Bookingnight Hi Im having some trouble with a model association - yes, I have tried the manual! For each Booking I have, I can have many Bookingnights *Booking* Booking.id *Bookingdate* Bookingdate.id Bookingdate.booking_id In my Booking model, I am able to get all the associated Bookingdates without issue. var $hasMany = array( 'Bookingdate' => array( 'className' => 'Bookingdates', 'foreignKey'=> 'booking_id', ) ); My problem is when I try and go back the other way. I have my Bookingdate.id, and want to get the associated booking. I would think that it should be belongsTo in my Bookingdate model? var $belongsTo = array( 'Booking' => array( 'className' => 'Bookings', 'foreignKey' => 'booking_id' ) ); ==> Doesnt Work Is there something obvious that I'm missing? On Wednesday, 27 June 2012 18:26:42 UTC+12, Sanfly wrote: > > Hi > > Im having some trouble with a model association - yes, I have tried the > manual! > > For each Booking I have, I can have many Bookingnights > > *Booking* > Booking.id > > > *Bookingnight* > Bookingnight.id > Bookingnight.booking_id > > In my Booking model, I am able to get all the associated Bookingnights > without issue. > > var $hasMany = array( > 'Bookingdate' => array( > 'className' => 'Bookingdates', > 'foreignKey'=> 'booking_id', > > ) > > ); > > My problem is when I try and go back the other way. I have my > Bookingnight.id, and want to get the associated booking. > > I would think that it should be belongsTo? > > var $belongsTo = array( > 'Booking' => array( > 'className' => 'Bookings', > 'foreignKey' => 'booking_id' > ) > > ); > > ==> Doesnt Work > > Is there something obvious that I'm missing? > > Thanks! > > > > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Model Associations Question
Hi Im having some trouble with a model association - yes, I have tried the manual! For each Booking I have, I can have many Bookingnights *Booking* Booking.id *Bookingnight* Bookingnight.id Bookingnight.booking_id In my Booking model, I am able to get all the associated Bookingnights without issue. var $hasMany = array( 'Bookingdate' => array( 'className' => 'Bookingdates', 'foreignKey'=> 'booking_id', ) ); My problem is when I try and go back the other way. I have my Bookingnight.id, and want to get the associated booking. I would think that it should be belongsTo? var $belongsTo = array( 'Booking' => array( 'className' => 'Bookings', 'foreignKey' => 'booking_id' ) ); ==> Doesnt Work Is there something obvious that I'm missing? Thanks! -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations
On Thu, May 24, 2012 at 7:37 PM, hill180 wrote: > Solved: But I don't know why. This but this code puts the data where I > want it, and without the index error: > Good to hear, glad I could help. Mike -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations
Solved: But I don't know why. This but this code puts the data where I want it, and without the index error: 'Contact' => array( 'className'=>'CONTACT', 'foreignKey' => false, 'finderQuery' => 'SELECT Account.AccountID as Contact__ACCOUNT_ID, contact.contact_full_name as Contact__CONTACT_FULL_NAME FROM CONTACTS AS contact LEFT JOIN Accounts AS Account ON contact.account_id=Account.account WHERE Account.AccountID = {$__cakeID__$}' ) On Thu, May 24, 2012 at 9:38 AM, hill180 wrote: > Ok. > Sorry for the last email. > > it made no sense: > > What I was trying to say is that I am getting > *Notice* (8): Undefined index: Contacts > > I copied the SQL Dumb (from the finderquery) in MSSQL Manager and it works. > > Just doing a debug($results) which is the results of the find query. > > Also it gets me 3 undefined Index errors, which matches the records for > this account. > > Thank you. > > > On Thu, May 24, 2012 at 10:33 AM, hill180 wrote: > >> Thank you so much. I think I am 99% there. >> >> Get the following error three times, (that is actually how many contacts >> are in the DB for the customer I was looking up. >> >> debug($results); >> >> *Notice* (8): Undefined index: Contacts [* >> CORE\Cake\Model\Datasource\DboSource.php*, line *1412*] >> Code Context >> >> }} else { >> $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin); >> >> $data = array( >> 'TblAccount' => array( >> ), >> 'Address' => array( >> ), >> 'Contacts' => array( >> ) >> ) >> $merge = array( >> (int) 0 => array( >> ), >> (int) 1 => array( >> ), >> (int) 2 => array( >> ) >> ) >> $association = 'Contacts' >> $type = 'hasMany' >> $selfJoin = false >> $i = (int) 1 >> $row = array( >> (int) 0 => array( >> ) >> ) >> $insert = array() >> >> DboSource::_mergeAssociation() - CORE\Cake\Model\Datasource\DboSource.php, >> line 1412 >> DboSource::queryAssociation() - CORE\Cake\Model\Datasource\DboSource.php, >> line 1274 >> DboSource::read() - CORE\Cake\Model\Datasource\DboSource.php, line 1087 >> Sqlserver::read() - CORE\Cake\Model\Datasource\Database\Sqlserver.php, line >> 600 >> Model::find() - CORE\Cake\Model\Model.php, line 2698 >> TblAccountsController::view() - APP\Controller\TblAccountsController.php, >> line 28 >> ReflectionMethod::invokeArgs() - [internal], line ?? >> Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 485 >> Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 103 >> Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 85 >> [main] - APP\webroot\index.php, line 92 >> >> >> >> >> >> >> >> Co >> >> I copied the SQL Dumb into MS SQL query and it gave me the records I >> needed. >> >> Thanks! >> >> >> On Thu, May 24, 2012 at 9:38 AM, Mike Griffin wrote: >> >>> On Thu, May 24, 2012 at 3:14 PM, hill180 wrote: >>> > Yes. >>> > >>> > As a disclaimer, I didn't write the original schema. >>> > >>> > Account_ID is for the systems account number (primary key) >>> > Account is for the logical account number (used by the company) >>> > >>> > The Account Address table use the Account_ID as the foreign key, but >>> the >>> > Contact Table uses the Account Number as the foreign key. >>> > >>> > SQLDUMP: >>> > >>> > SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME], >>> > [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM >>> > [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] = >>> [Accounts].[Account] >>> > >>> > >>> > error: >>> > >>> > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client >>> > 11.0][SQL Server]The multi-part identifier "Accounts.Account" could >>> not be >>> > bound. >>> > >>> >>> Right so. >>> >>> You can do it this way instead. Remove the conditions array from the >>> model association and put this in: >>> 'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT >>> JOIN accounts AS Account ON Contact.account_id=Account.account WHERE >>> Account.AccountID = {$__cakeID__$}' >>> >>> You can edit the SELECT query to return whatever values you want but >>> leave in the {$__cakeID__$} bit as it is the value of the primary key. >>> >>> I hope this makes sense. >>> >>> Mike. >>> >>> -- >>> Our newest site for the community: CakePHP Video Tutorials >>> http://tv.cakephp.org >>> Check out the new CakePHP Questions site http://ask.cakephp.org and >>> help others with their CakePHP related questions. >>> >>> >>> To unsubscribe from this group, send email to >>> cake-php+unsubscr...@googlegroups.com For more options, visit this >>> group at http://groups.google.com/group/cake-php >>> >> >> > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+u
Re: Model Associations
Ok. Sorry for the last email. it made no sense: What I was trying to say is that I am getting *Notice* (8) : Undefined index: Contacts I copied the SQL Dumb (from the finderquery) in MSSQL Manager and it works. Just doing a debug($results) which is the results of the find query. Also it gets me 3 undefined Index errors, which matches the records for this account. Thank you. On Thu, May 24, 2012 at 10:33 AM, hill180 wrote: > Thank you so much. I think I am 99% there. > > Get the following error three times, (that is actually how many contacts > are in the DB for the customer I was looking up. > > debug($results); > > *Notice* (8): Undefined index: Contacts [* > CORE\Cake\Model\Datasource\DboSource.php*, line *1412*] > Code Context > > }} else { > $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin); > > $data = array( > 'TblAccount' => array( > ), > 'Address' => array( > ), > 'Contacts' => array( > ) > ) > $merge = array( > (int) 0 => array( > ), > (int) 1 => array( > ), > (int) 2 => array( > ) > ) > $association = 'Contacts' > $type = 'hasMany' > $selfJoin = false > $i = (int) 1 > $row = array( > (int) 0 => array( > ) > ) > $insert = array() > > DboSource::_mergeAssociation() - CORE\Cake\Model\Datasource\DboSource.php, > line 1412 > DboSource::queryAssociation() - CORE\Cake\Model\Datasource\DboSource.php, > line 1274 > DboSource::read() - CORE\Cake\Model\Datasource\DboSource.php, line 1087 > Sqlserver::read() - CORE\Cake\Model\Datasource\Database\Sqlserver.php, line > 600 > Model::find() - CORE\Cake\Model\Model.php, line 2698 > TblAccountsController::view() - APP\Controller\TblAccountsController.php, > line 28 > ReflectionMethod::invokeArgs() - [internal], line ?? > Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 485 > Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 103 > Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 85 > [main] - APP\webroot\index.php, line 92 > > > > > > > > Co > > I copied the SQL Dumb into MS SQL query and it gave me the records I > needed. > > Thanks! > > > On Thu, May 24, 2012 at 9:38 AM, Mike Griffin wrote: > >> On Thu, May 24, 2012 at 3:14 PM, hill180 wrote: >> > Yes. >> > >> > As a disclaimer, I didn't write the original schema. >> > >> > Account_ID is for the systems account number (primary key) >> > Account is for the logical account number (used by the company) >> > >> > The Account Address table use the Account_ID as the foreign key, but the >> > Contact Table uses the Account Number as the foreign key. >> > >> > SQLDUMP: >> > >> > SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME], >> > [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM >> > [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] = >> [Accounts].[Account] >> > >> > >> > error: >> > >> > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client >> > 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not >> be >> > bound. >> > >> >> Right so. >> >> You can do it this way instead. Remove the conditions array from the >> model association and put this in: >> 'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT >> JOIN accounts AS Account ON Contact.account_id=Account.account WHERE >> Account.AccountID = {$__cakeID__$}' >> >> You can edit the SELECT query to return whatever values you want but >> leave in the {$__cakeID__$} bit as it is the value of the primary key. >> >> I hope this makes sense. >> >> Mike. >> >> -- >> Our newest site for the community: CakePHP Video Tutorials >> http://tv.cakephp.org >> Check out the new CakePHP Questions site http://ask.cakephp.org and help >> others with their CakePHP related questions. >> >> >> To unsubscribe from this group, send email to >> cake-php+unsubscr...@googlegroups.com For more options, visit this group >> at http://groups.google.com/group/cake-php >> > > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations
Thank you so much. I think I am 99% there. Get the following error three times, (that is actually how many contacts are in the DB for the customer I was looking up. debug($results); *Notice* (8) : Undefined index: Contacts [* CORE\Cake\Model\Datasource\DboSource.php*, line *1412*] Code Context }} else { $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin); $data = array( 'TblAccount' => array( ), 'Address' => array( ), 'Contacts' => array( ) ) $merge = array( (int) 0 => array( ), (int) 1 => array( ), (int) 2 => array( ) ) $association = 'Contacts' $type = 'hasMany' $selfJoin = false $i = (int) 1 $row = array( (int) 0 => array( ) ) $insert = array() DboSource::_mergeAssociation() - CORE\Cake\Model\Datasource\DboSource.php, line 1412 DboSource::queryAssociation() - CORE\Cake\Model\Datasource\DboSource.php, line 1274 DboSource::read() - CORE\Cake\Model\Datasource\DboSource.php, line 1087 Sqlserver::read() - CORE\Cake\Model\Datasource\Database\Sqlserver.php, line 600 Model::find() - CORE\Cake\Model\Model.php, line 2698 TblAccountsController::view() - APP\Controller\TblAccountsController.php, line 28 ReflectionMethod::invokeArgs() - [internal], line ?? Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 485 Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 103 Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 85 [main] - APP\webroot\index.php, line 92 Co I copied the SQL Dumb into MS SQL query and it gave me the records I needed. Thanks! On Thu, May 24, 2012 at 9:38 AM, Mike Griffin wrote: > On Thu, May 24, 2012 at 3:14 PM, hill180 wrote: > > Yes. > > > > As a disclaimer, I didn't write the original schema. > > > > Account_ID is for the systems account number (primary key) > > Account is for the logical account number (used by the company) > > > > The Account Address table use the Account_ID as the foreign key, but the > > Contact Table uses the Account Number as the foreign key. > > > > SQLDUMP: > > > > SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME], > > [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM > > [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] = > [Accounts].[Account] > > > > > > error: > > > > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client > > 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not > be > > bound. > > > > Right so. > > You can do it this way instead. Remove the conditions array from the > model association and put this in: > 'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT > JOIN accounts AS Account ON Contact.account_id=Account.account WHERE > Account.AccountID = {$__cakeID__$}' > > You can edit the SELECT query to return whatever values you want but > leave in the {$__cakeID__$} bit as it is the value of the primary key. > > I hope this makes sense. > > Mike. > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > at http://groups.google.com/group/cake-php > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations
On Thu, May 24, 2012 at 3:14 PM, hill180 wrote: > Yes. > > As a disclaimer, I didn't write the original schema. > > Account_ID is for the systems account number (primary key) > Account is for the logical account number (used by the company) > > The Account Address table use the Account_ID as the foreign key, but the > Contact Table uses the Account Number as the foreign key. > > SQLDUMP: > > SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME], > [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM > [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] = [Accounts].[Account] > > > error: > > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client > 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not be > bound. > Right so. You can do it this way instead. Remove the conditions array from the model association and put this in: 'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT JOIN accounts AS Account ON Contact.account_id=Account.account WHERE Account.AccountID = {$__cakeID__$}' You can edit the SELECT query to return whatever values you want but leave in the {$__cakeID__$} bit as it is the value of the primary key. I hope this makes sense. Mike. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations
Yes. As a disclaimer, I didn't write the original schema. Account_ID is for the systems account number (primary key) Account is for the logical account number (used by the company) The Account Address table use the Account_ID as the foreign key, but the Contact Table uses the Account Number as the foreign key. SQLDUMP: SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME], [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] = [Accounts].[Account] error: Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not be bound. On Thu, May 24, 2012 at 3:28 AM, Mike Griffin wrote: > On Thu, May 24, 2012 at 1:50 AM, hill180 wrote: > > AccountID = AccountID on the Account and the Address for the Account, no > > problems here. > > > > > > The problem is the contacts. > > > > The join is Contact.Account_id = Accounts.Account (not Account_ID) > > > > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL > > Server]The multi-part identifier "Accounts.Account" could not be bound. > > > > Are you saying that the Accounts.Account and Accounts.AccountID are > different fields and have different values? > > What's the actual SQL statement that is being created and causes the error? > > Mike. > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > at http://groups.google.com/group/cake-php > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations
On Thu, May 24, 2012 at 1:50 AM, hill180 wrote: > AccountID = AccountID on the Account and the Address for the Account, no > problems here. > > > The problem is the contacts. > > The join is Contact.Account_id = Accounts.Account (not Account_ID) > > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL > Server]The multi-part identifier "Accounts.Account" could not be bound. > Are you saying that the Accounts.Account and Accounts.AccountID are different fields and have different values? What's the actual SQL statement that is being created and causes the error? Mike. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Model Associations
*Cake *PHP 2. *public *$useTable = 'Accounts'; /** * Primary key field * * *@var* string */ *public *$primaryKey = 'AccountID'; *public *$hasMany = *array*( 'Address' => *array*( 'className' => 'AccountAddress', 'foreignKey' => 'AccountID', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Contact' => *array*( 'className' => 'CONTACT', 'foreignKey' => false, 'conditions'=>*array*( 'Contact.ACCOUNT_ID = Accounts.Account') ) ); The Database was from an existing system. AccountID = AccountID on the Account and the Address for the Account, no problems here. The problem is the contacts. The join is Contact.Account_id = Accounts.Account (not Account_ID) *Error: *SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not be bound. This join will always exist so I want to create it in the model class. I am not able to change any DB Structure. Thanks. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations and Inserting through Associations
If user is not logged in, then in Event form: echo $this->Form->input('Event.user_id', array('type' => 'hidden', 'value' => $user['User']['id'])); and in controller: $this->Event->create($this->request->data); if ($this->Event->save()) { ... Do not forget to use SecurityComponent in AppController, so nobody can change value of that hidden field in browser. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations and Inserting through Associations
I should have specified - the user doesn't necessarily have to be the logged in user. It could be any user, in which case $this->Auth->user('id') doesn't fit my needs. This is closer, I just need to figure out how to grab the user id from the users/view page. On Saturday, May 5, 2012 10:33:09 AM UTC-6, stork wrote: > > $this->Event->create($this->request->data); > $this->Event->set('user_id', $this->Auth->user('id')); > if ($this->Event->save()) { > ... > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations and Inserting through Associations
Trying to learn it through straight code before I dive into any console commands. One of the biggest reasons that I've put off using MVC is because I like to feel like I'm in control. Yes, probably dumb, but it makes more sense to my fragile brain. On Saturday, May 5, 2012 7:57:13 AM UTC-6, Michael wrote: > > You should take some time to learn how to use bake. It will setup the > basics for you based on your database and will serve as a great > example of how to do things. > > > http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html > > > There are many tutorials out there about setting it up. > > ~Michael > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations and Inserting through Associations
$this->Event->create($this->request->data); $this->Event->set('user_id', $this->Auth->user('id')); if ($this->Event->save()) { ... -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model Associations and Inserting through Associations
You should take some time to learn how to use bake. It will setup the basics for you based on your database and will serve as a great example of how to do things. http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html There are many tutorials out there about setting it up. ~Michael -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Model Associations and Inserting through Associations
MVC Beginner here - I have created a database with a USER table which hasMany EVENTS, and conversely have set the EVENTS belongsTo USER Here's my question: When I want to add an event from a user page (users/view), how do I automatically associate that event(event/add) with the user in the database? I know that it makes the foreign key connection with a user_id field in the events table, but I don't know how to get to the event/add page and carry/apply the user id to the form helper. Am I making any sense here? Thanks in advance. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: multi-level Model associations behavior
On Tue, Mar 27, 2012 at 20:40, Augey Mikus wrote: > I am building an eLearning site in CakePHP that has models: Course, > Test, Question, Answer, and others. > > Here are my associations: > > Course hasMany Test > Test belongsTo Course > Question belongsTo Test > Question hasMany Answer > Answer belongsTo Question > > As you can see, the $test array in my view stops at Question, and > doesn't pull the associated Answer(s) for the Question(s). > You could try to use the Containable Behaviour (http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html) $this->Test->find( 'all', array( 'contain' => array( 'Course', 'Question' => array( 'Answer' ) ) ), 'conditions' => array( 'Test.id' => $id ) ); That should bring back the proper array with the answers corresponding to each question. Mike. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: multi-level Model associations behavior
you could replace $test = $this->Test->read(null, $id); $test['Question'] = $this->Test->Question->find('all'); //I added this line... with $test = $this->Test->find('first', array( 'conditions'=>array('id'=>$id), 'recursive'=2 )); the conditions array indicates which test records to get and the recursive value indications how deep many levels of associates it should fetch. If you don't specify it will get them all. On Tue, Mar 27, 2012 at 2:40 PM, Augey Mikus wrote: > I am building an eLearning site in CakePHP that has models: Course, > Test, Question, Answer, and others. > > Here are my associations: > > Course hasMany Test > Test belongsTo Course > Question belongsTo Test > Question hasMany Answer > Answer belongsTo Question > > This model association works fine in most circumstances. For example, > the baked CRUD actions for Course know that there are Test(s) that > belong to it, Questions know they have associated Answer(s), etc... > > But I am trying to write a Test management tool that operates within > the TestsController and level of association ends at Question. There > are no answers. In other words, the view I'm working on has this by > default from the baked TestsController: > > Array > ( >[Test] => Array >( >[id] => 1 >[name] => Test 1 >[course_id] => 1 >[time_limit] => 30 >[max_questions] => 20 >[randomize_order] => 1 >[num_questions] => 2 >) > >[Course] => Array >( >[id] => 1 >[course_identifier] => TLE1001 >[title] => Child Development I >[description] => >) > >[Question] => Array >( >[0] => Array >( >[id] => 1 >[text] => What is your name? >[test_id] => 1 >[order] => 0 >) > >[1] => Array >( >[id] => 2 >[text] => What is my name? >[test_id] => 1 >[order] => 0 >) > >) > > ) > > As you can see, the $test array in my view stops at Question, and > doesn't pull the associated Answer(s) for the Question(s). > > I fixed this problem by changing the bottom of my 'view' action in > TestsController: > > $test = $this->Test->read(null, $id); > $test['Question'] = $this->Test->Question->find('all'); //I added this > line... > $this->set('test', $test); > > I added the middle line so it literally replaces all the contents of > $test['Question'] manually before it sets the $test array for the view > to use. > > That works for what I have to accomplish, but it seems ugly to me. Is > there a better way to do this? Does CakePHP only build associated > data array's for model association up to a certain level then stop? > > P.S. I tried to add: > > var $uses = array('Test', 'Question', 'Answer'); > > ...to the top of my TestsController but it did not fix the problem and > seemed to have no effect. > > > > > > > > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > at http://groups.google.com/group/cake-php > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
multi-level Model associations behavior
I am building an eLearning site in CakePHP that has models: Course, Test, Question, Answer, and others. Here are my associations: Course hasMany Test Test belongsTo Course Question belongsTo Test Question hasMany Answer Answer belongsTo Question This model association works fine in most circumstances. For example, the baked CRUD actions for Course know that there are Test(s) that belong to it, Questions know they have associated Answer(s), etc... But I am trying to write a Test management tool that operates within the TestsController and level of association ends at Question. There are no answers. In other words, the view I'm working on has this by default from the baked TestsController: Array ( [Test] => Array ( [id] => 1 [name] => Test 1 [course_id] => 1 [time_limit] => 30 [max_questions] => 20 [randomize_order] => 1 [num_questions] => 2 ) [Course] => Array ( [id] => 1 [course_identifier] => TLE1001 [title] => Child Development I [description] => ) [Question] => Array ( [0] => Array ( [id] => 1 [text] => What is your name? [test_id] => 1 [order] => 0 ) [1] => Array ( [id] => 2 [text] => What is my name? [test_id] => 1 [order] => 0 ) ) ) As you can see, the $test array in my view stops at Question, and doesn't pull the associated Answer(s) for the Question(s). I fixed this problem by changing the bottom of my 'view' action in TestsController: $test = $this->Test->read(null, $id); $test['Question'] = $this->Test->Question->find('all'); //I added this line... $this->set('test', $test); I added the middle line so it literally replaces all the contents of $test['Question'] manually before it sets the $test array for the view to use. That works for what I have to accomplish, but it seems ugly to me. Is there a better way to do this? Does CakePHP only build associated data array's for model association up to a certain level then stop? P.S. I tried to add: var $uses = array('Test', 'Question', 'Answer'); ...to the top of my TestsController but it did not fix the problem and seemed to have no effect. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Cake 1.3 - Complicated Model associations
I think I may have just answered my own question in writing that! If I use the 2 model & added a beforeSave to set the type when saving to set the 'type' field. & the condition on the relationship, then each of the ticket type models will not be able to see the transactions that relate to the other type. Still open to comment & correction though... -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Cake 1.3 - Complicated Model associations
Hi there, Am have a dilemma... I have a store that sells eTickets & physical tickets. Details of the sale of each type of ticket are stored in 2 tables (etickets & ptickets). I also have a table that stores details of when a user is directed off to PayPal to pay for their tickets (paypal_transactions). I've been trying to work out the best way to setup the relationships here. Originally I setup 2 join tables between the paypal_transactions & the different ticket types tables, with a HABTM relationship, however this doesn't quite feel right, as there can be many transactions per ticker (if payments fail), but not multiple tickets per transaction. My other thoughts on options were... 1. Add a eticket_id & a pticket_id field to the transactions table (but this does not securely stop a transaction having both a eticket_id & a pticket_id). 2. Add a 'type' column in the paypal_transactions for 'ticket_type' & then setup 2 models for the transactions table with some kind of filter on the find methods to limit it to only the appropriate record 2a. As 2, but have a single model & use the conditions property of the hasMany association to limit the records returned. None of these options seem to protect against a transaction being associated to both an eticket & a pticket at the same time, & whenever I've tried to add validation to a foreignKey field in the past it's caused problems with my saveAll statements. Any help of advice on this one would be greatly appreciated. Thanks, T -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Conditions in model associations
you could probably wright a behavior which could "correct" the issue at runtime until it is fixed in the not so near future :) On 30 Nov., 06:59, Jeremy Burns | Class Outfit wrote: > Thanks - this is exactly the issue I am facing. I agree with you; this sort > of renders the conditional associations almost useless and I bet it catches a > lot of people out. It took me an hour or so to realise what was happening. > > Jeremy Burns > Class Outfit > > http://www.classoutfit.com > > On 29 Nov 2011, at 21:25, euromark wrote: > > > > > > > > > and I think this is the ticket: > >http://cakephp.lighthouseapp.com/projects/42648/tickets/1793-model-co... > > > On 29 Nov., 22:22, euromark wrote: > >> If I remember right a core member once wrote that this is a known > >> limitation of the current "conditions array" for relations. > >> Personally, I think this should be addressed in 2.1 as a bugfix to be > >> fixed (if I add a global condition it should always be applied, no > >> matter what). > > >> As of right now you probably need to manually join the conditions. > > >> On 29 Nov., 18:16, Jeremy Burns wrote: > > >>> I've noticed that if I have conditions on model associations, for > >>> example: > > >>> $hasMany = array( > >>> 'ActiveUser' => array( > >>> 'className' => 'User', > >>> 'foreignKey' => 'group_id', > >>> 'conditions' => array( > >>> 'ActiveUser.active' => 1 > >>> ) > >>> ) > >>> ); > > >>> ...and bring that key into a find BUT with an added condition, for > >>> example; > > >>> $groups = $this->find( > >>> 'all', > >>> array( > >>> 'contain' => array( > >>> 'ActiveUser' => array( > >>> 'conditions' => array( > >>> 'ActiveUser.id' => 10 > >>> ) > >>> ) > >>> ) > >>> ) > >>> ); > > >>> ...the condition on the join is ignored. So in this example the user > >>> with an id of 10 will come back whether he is active or not. > > >>> How do I overcome that? > > > -- > > Our newest site for the community: CakePHP Video > > Tutorialshttp://tv.cakephp.org > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Conditions in model associations
Thanks - this is exactly the issue I am facing. I agree with you; this sort of renders the conditional associations almost useless and I bet it catches a lot of people out. It took me an hour or so to realise what was happening. Jeremy Burns Class Outfit http://www.classoutfit.com On 29 Nov 2011, at 21:25, euromark wrote: > and I think this is the ticket: > http://cakephp.lighthouseapp.com/projects/42648/tickets/1793-model-conditions-not-recursively-applied > > > On 29 Nov., 22:22, euromark wrote: >> If I remember right a core member once wrote that this is a known >> limitation of the current "conditions array" for relations. >> Personally, I think this should be addressed in 2.1 as a bugfix to be >> fixed (if I add a global condition it should always be applied, no >> matter what). >> >> As of right now you probably need to manually join the conditions. >> >> On 29 Nov., 18:16, Jeremy Burns wrote: >> >> >> >> >> >> >> >>> I've noticed that if I have conditions on model associations, for >>> example: >> >>> $hasMany = array( >>> 'ActiveUser' => array( >>> 'className' => 'User', >>> 'foreignKey' => 'group_id', >>> 'conditions' => array( >>> 'ActiveUser.active' => 1 >>> ) >>> ) >>> ); >> >>> ...and bring that key into a find BUT with an added condition, for >>> example; >> >>> $groups = $this->find( >>> 'all', >>> array( >>> 'contain' => array( >>> 'ActiveUser' => array( >>> 'conditions' => array( >>> 'ActiveUser.id' => 10 >>> ) >>> ) >>> ) >>> ) >>> ); >> >>> ...the condition on the join is ignored. So in this example the user >>> with an id of 10 will come back whether he is active or not. >> >>> How do I overcome that? > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Conditions in model associations
and I think this is the ticket: http://cakephp.lighthouseapp.com/projects/42648/tickets/1793-model-conditions-not-recursively-applied On 29 Nov., 22:22, euromark wrote: > If I remember right a core member once wrote that this is a known > limitation of the current "conditions array" for relations. > Personally, I think this should be addressed in 2.1 as a bugfix to be > fixed (if I add a global condition it should always be applied, no > matter what). > > As of right now you probably need to manually join the conditions. > > On 29 Nov., 18:16, Jeremy Burns wrote: > > > > > > > > > I've noticed that if I have conditions on model associations, for > > example: > > > $hasMany = array( > > 'ActiveUser' => array( > > 'className' => 'User', > > 'foreignKey' => 'group_id', > > 'conditions' => array( > > 'ActiveUser.active' => 1 > > ) > > ) > > ); > > > ...and bring that key into a find BUT with an added condition, for > > example; > > > $groups = $this->find( > > 'all', > > array( > > 'contain' => array( > > 'ActiveUser' => array( > > 'conditions' => array( > > 'ActiveUser.id' => 10 > > ) > > ) > > ) > > ) > > ); > > > ...the condition on the join is ignored. So in this example the user > > with an id of 10 will come back whether he is active or not. > > > How do I overcome that? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Conditions in model associations
If I remember right a core member once wrote that this is a known limitation of the current "conditions array" for relations. Personally, I think this should be addressed in 2.1 as a bugfix to be fixed (if I add a global condition it should always be applied, no matter what). As of right now you probably need to manually join the conditions. On 29 Nov., 18:16, Jeremy Burns wrote: > I've noticed that if I have conditions on model associations, for > example: > > $hasMany = array( > 'ActiveUser' => array( > 'className' => 'User', > 'foreignKey' => 'group_id', > 'conditions' => array( > 'ActiveUser.active' => 1 > ) > ) > ); > > ...and bring that key into a find BUT with an added condition, for > example; > > $groups = $this->find( > 'all', > array( > 'contain' => array( > 'ActiveUser' => array( > 'conditions' => array( > 'ActiveUser.id' => 10 > ) > ) > ) > ) > ); > > ...the condition on the join is ignored. So in this example the user > with an id of 10 will come back whether he is active or not. > > How do I overcome that? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Conditions in model associations
I've noticed that if I have conditions on model associations, for example: $hasMany = array( 'ActiveUser' => array( 'className' => 'User', 'foreignKey' => 'group_id', 'conditions' => array( 'ActiveUser.active' => 1 ) ) ); ...and bring that key into a find BUT with an added condition, for example; $groups = $this->find( 'all', array( 'contain' => array( 'ActiveUser' => array( 'conditions' => array( 'ActiveUser.id' => 10 ) ) ) ) ); ...the condition on the join is ignored. So in this example the user with an id of 10 will come back whether he is active or not. How do I overcome that? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: HELP! model associations lost after import
Your first two examples will not work as models are not plural. http://book.cakephp.org/view/936/Importing-Controllers-Models-Components-Behaviors- HTH, Paul. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: HELP! model associations lost after import
Not sure what the issue is, but in general I'd recommend that you set recursive to -1 in your app_model and then use the Containable behaviour; it gives you total control and my well solve your issue (as well as bring other improvements). Jeremy Burns Class Outfit http://www.classoutfit.com On 16 Nov 2011, at 23:36, billy wrote: > Due to a client's desire to have URLs that defy Cake logic, i have > decided to use the pages controller to organize my app. > most the site's functionality occurs from one page through ajax so i > thought i'd use pages as the home base and access other controllers > and models. > > so i decided to import the relevant models. > > i have tried all three methods: > > > $this->loadModel('Inventories'); > > $Inventories =& ClassRegistry::init('Inventories'); > > App::import('Controller', 'Inventories'); > $Inventories = new InventoriesController; > > > Model seems to load fine but when i try to find some records: > > > $(...)->find("all", array( > 'conditions' => array('id' => '1'), > 'recursive'=>2) > ); > > > i only get results as if recursive had been -1 > or as if there were no other associated models > this happens no matter what level of recursive i put > and when i load the model in regular controllers, i get an appropriate > response. > > any ideas how i can change my pages controller to retrieve associated > models like regular controllers? > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
HELP! model associations lost after import
Due to a client's desire to have URLs that defy Cake logic, i have decided to use the pages controller to organize my app. most the site's functionality occurs from one page through ajax so i thought i'd use pages as the home base and access other controllers and models. so i decided to import the relevant models. i have tried all three methods: $this->loadModel('Inventories'); $Inventories =& ClassRegistry::init('Inventories'); App::import('Controller', 'Inventories'); $Inventories = new InventoriesController; Model seems to load fine but when i try to find some records: $(...)->find("all", array( 'conditions' => array('id' => '1'), 'recursive'=>2) ); i only get results as if recursive had been -1 or as if there were no other associated models this happens no matter what level of recursive i put and when i load the model in regular controllers, i get an appropriate response. any ideas how i can change my pages controller to retrieve associated models like regular controllers? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model associations and combobox.
On Sat, Apr 16, 2011 at 2:34 PM, cricket wrote: > > public function add() > { > if (!empty($this->data)) > { > // attempt to save > } > > $this->set( > 'fabricantes', > $this->Carro->Fabricante->find('list') > ); > } > > echo $this->Form->select('Carro.fabricante_id', $fabricantes); > One other thing. For find('list') Cake fetches the primary key (usually id) and the "display field" which defaults to a colmn called "name". So you'll need to do this in Carro model: public $displayField = 'nome'; -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Model associations and combobox.
On Fri, Apr 15, 2011 at 10:45 AM, Uriel Juliatti wrote: > Hey everybody > > I'd like to know how to display a list of > Manufacturers (associated with Cars) in a combobox when I create cars. > > My Mysql query returns it: > > SELECT `Carro`.`id`, `Carro`.`fabricante_id`, `Carro`.`nome`, > `Carro`.`modelo`, `Carro`.`blindado`, `Carro`.`cor`, `Carro`.`ano`, > `Carro`.`preco`, `Fabricante`.`id`, `Fabricante`.`nome` FROM `carros` > AS `Carro` LEFT JOIN `fabricantes` AS `Fabricante` ON > (`Carro`.`fabricante_id` = `Fabricante`.`id`) WHERE 1 = 1 > > // Where fabricante = Manufacturer and Carro = Car. > > My models are: > > models/carro.php: > class Carro extends AppModel > { > var $name = "Carro"; > var $belongsTo = 'Fabricante'; > } > > models/fabricante.php: > > class Fabricante extends AppModel > { > var $name = "Fabricante"; > var $hasMany = array('Carro' => array( > 'className' => 'Carro', > 'foreignKey' => 'fabricante_id', > 'dependent'=> true > ) > ); > } > > Does anyone have any idea how to display the Manufacturers into a > combobox at Cars 'add' view? public function add() { if (!empty($this->data)) { // attempt to save } $this->set( 'fabricantes', $this->Carro->Fabricante->find('list') ); } echo $this->Form->select('Carro.fabricante_id', $fabricantes); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Model associations and combobox.
Hey everybody I'd like to know how to display a list of Manufacturers (associated with Cars) in a combobox when I create cars. My Mysql query returns it: SELECT `Carro`.`id`, `Carro`.`fabricante_id`, `Carro`.`nome`, `Carro`.`modelo`, `Carro`.`blindado`, `Carro`.`cor`, `Carro`.`ano`, `Carro`.`preco`, `Fabricante`.`id`, `Fabricante`.`nome` FROM `carros` AS `Carro` LEFT JOIN `fabricantes` AS `Fabricante` ON (`Carro`.`fabricante_id` = `Fabricante`.`id`) WHERE 1 = 1 // Where fabricante = Manufacturer and Carro = Car. My models are: models/carro.php: class Carro extends AppModel { var $name = "Carro"; var $belongsTo = 'Fabricante'; } models/fabricante.php: class Fabricante extends AppModel { var $name = "Fabricante"; var $hasMany = array('Carro' => array( 'className' => 'Carro', 'foreignKey'=> 'fabricante_id', 'dependent'=> true ) ); } Does anyone have any idea how to display the Manufacturers into a combobox at Cars 'add' view? I only know how to do it in Ruby on Rails and it seems kind of different to implement. Best wishes, Uriel -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: How to properly use "conditions" in model associations
Awesome, thanks everyone! I think I'm going to opt for removing the associating and just taking care of it in my queries. On Mar 2, 5:34 pm, euromark wrote: > i agree with gremlin > foreign_key + model is an example for this > > everything else i would set right inside the querying model method > > On 2 Mrz., 23:06, gremlin wrote: > > > > > > > > > I tend to define conditions in associations on very few occasions. One > > good use is for polymorphic models (you need to define the field => > > modelName mapping) and for models that have a enum field (or similar) > > that determines some behavior of the model. IE log models and for > > defining self referencing tables where I tend to use an relationship > > alias (ParentNode, ChildNode) > > > This isn't the only time you might define conditions in the > > relationship but these are the only ones that pop to mind. > > > On Mar 2, 11:43 am, "Krissy Masters" > > wrote: > > > > Personaly I never set any conditions in the relations (hasOne, hasMany > > > ) > > > > all conditions are defined in the function since depending on why I am > > > getting the data and for who conditions constantly change. > > > > You can say conditions Posts => 1 //active so you only by default display > > > all active Post. > > > > but then when its time to get all users posts so they can edit their data > > > you need to set condition where Post.id => $user_id. If you kept the > > > regular > > > condition you would only pull that users active posts not all. > > > > But I just developed from day 1 like this so also would be curious to see > > > what others are doing in regards to the other params available for > > > relations. > > > > Good question :) > > > > K > > > > -Original Message- > > > From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On > > > Behalf > > > > Of Eric Anderson > > > Sent: Wednesday, March 02, 2011 3:57 PM > > > To: CakePHP > > > Subject: How to properly use "conditions" in model associations > > > > Hi everyone, > > > > I'm wondering what is the 'proper' or 'suggested' way of using > > > "conditions" in model associations. I'm using an Activity model to log > > > activities performed throughout my app. I then use this table to > > > output activity feed / notifications style sections to users. The > > > problem I'm having is that Cake throws a "column not found" error (I > > > guess technically it's MySQL throwing the error). When running a > > > query, Cake for some reason formulates the query so that MySQL is > > > looking for columns from my Activity table inside of other tables. Do > > > I need to specify "conditions" in both my User and Activity model, as > > > shown below? When I remove the conditions from the Activity model, > > > everything runs fine. > > > > > > > class Activity extends AppModel { > > > > var $name = 'Activity'; > > > var $actsAs = array('Containable'); > > > > var $belongsTo = array( > > > > // Doers > > > 'User' => array( > > > 'className' => 'User', > > > 'foreignKey' => 'doer_id', > > > 'conditions' => array('Activity.doer_table' => > > > 'users') > > > ) > > > } > > > ?> > > > > > > > class User extends AppModel { > > > > var $name = 'User'; > > > var $actsAs = array('Containable'); > > > > var $hasMany = array( > > > 'Activity' => array( > > > 'className' => 'Activity', > > > 'foreignKey' => 'doer_id', > > > 'conditions' => array( > > > 'Activity.doer_table' => 'users' > > > ), > > > 'dependent' => true > > > ); > > > } > > > ?> > > > > -- > > > Our newest site for the community: CakePHP Video > > > Tutorialshttp://tv.cakephp.org > > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp > > > others with their CakePHP related questions. > > > > To unsubscribe from this group, send email to > > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: How to properly use "conditions" in model associations
i agree with gremlin foreign_key + model is an example for this everything else i would set right inside the querying model method On 2 Mrz., 23:06, gremlin wrote: > I tend to define conditions in associations on very few occasions. One > good use is for polymorphic models (you need to define the field => > modelName mapping) and for models that have a enum field (or similar) > that determines some behavior of the model. IE log models and for > defining self referencing tables where I tend to use an relationship > alias (ParentNode, ChildNode) > > This isn't the only time you might define conditions in the > relationship but these are the only ones that pop to mind. > > On Mar 2, 11:43 am, "Krissy Masters" > wrote: > > > > > > > > > Personaly I never set any conditions in the relations (hasOne, hasMany ) > > > all conditions are defined in the function since depending on why I am > > getting the data and for who conditions constantly change. > > > You can say conditions Posts => 1 //active so you only by default display > > all active Post. > > > but then when its time to get all users posts so they can edit their data > > you need to set condition where Post.id => $user_id. If you kept the regular > > condition you would only pull that users active posts not all. > > > But I just developed from day 1 like this so also would be curious to see > > what others are doing in regards to the other params available for > > relations. > > > Good question :) > > > K > > > -Original Message- > > From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf > > > Of Eric Anderson > > Sent: Wednesday, March 02, 2011 3:57 PM > > To: CakePHP > > Subject: How to properly use "conditions" in model associations > > > Hi everyone, > > > I'm wondering what is the 'proper' or 'suggested' way of using > > "conditions" in model associations. I'm using an Activity model to log > > activities performed throughout my app. I then use this table to > > output activity feed / notifications style sections to users. The > > problem I'm having is that Cake throws a "column not found" error (I > > guess technically it's MySQL throwing the error). When running a > > query, Cake for some reason formulates the query so that MySQL is > > looking for columns from my Activity table inside of other tables. Do > > I need to specify "conditions" in both my User and Activity model, as > > shown below? When I remove the conditions from the Activity model, > > everything runs fine. > > > > > class Activity extends AppModel { > > > var $name = 'Activity'; > > var $actsAs = array('Containable'); > > > var $belongsTo = array( > > > // Doers > > 'User' => array( > > 'className' => 'User', > > 'foreignKey' => 'doer_id', > > 'conditions' => array('Activity.doer_table' => > > 'users') > > ) > > } > > ?> > > > > > class User extends AppModel { > > > var $name = 'User'; > > var $actsAs = array('Containable'); > > > var $hasMany = array( > > 'Activity' => array( > > 'className' => 'Activity', > > 'foreignKey' => 'doer_id', > > 'conditions' => array( > > 'Activity.doer_table' => 'users' > > ), > > 'dependent' => true > > ); > > } > > ?> > > > -- > > Our newest site for the community: CakePHP Video > > Tutorialshttp://tv.cakephp.org > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp > > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: How to properly use "conditions" in model associations
I tend to define conditions in associations on very few occasions. One good use is for polymorphic models (you need to define the field => modelName mapping) and for models that have a enum field (or similar) that determines some behavior of the model. IE log models and for defining self referencing tables where I tend to use an relationship alias (ParentNode, ChildNode) This isn't the only time you might define conditions in the relationship but these are the only ones that pop to mind. On Mar 2, 11:43 am, "Krissy Masters" wrote: > Personaly I never set any conditions in the relations (hasOne, hasMany ) > > all conditions are defined in the function since depending on why I am > getting the data and for who conditions constantly change. > > You can say conditions Posts => 1 //active so you only by default display > all active Post. > > but then when its time to get all users posts so they can edit their data > you need to set condition where Post.id => $user_id. If you kept the regular > condition you would only pull that users active posts not all. > > But I just developed from day 1 like this so also would be curious to see > what others are doing in regards to the other params available for > relations. > > Good question :) > > K > > -Original Message- > From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf > > Of Eric Anderson > Sent: Wednesday, March 02, 2011 3:57 PM > To: CakePHP > Subject: How to properly use "conditions" in model associations > > Hi everyone, > > I'm wondering what is the 'proper' or 'suggested' way of using > "conditions" in model associations. I'm using an Activity model to log > activities performed throughout my app. I then use this table to > output activity feed / notifications style sections to users. The > problem I'm having is that Cake throws a "column not found" error (I > guess technically it's MySQL throwing the error). When running a > query, Cake for some reason formulates the query so that MySQL is > looking for columns from my Activity table inside of other tables. Do > I need to specify "conditions" in both my User and Activity model, as > shown below? When I remove the conditions from the Activity model, > everything runs fine. > > > class Activity extends AppModel { > > var $name = 'Activity'; > var $actsAs = array('Containable'); > > var $belongsTo = array( > > // Doers > 'User' => array( > 'className' => 'User', > 'foreignKey' => 'doer_id', > 'conditions' => array('Activity.doer_table' => > 'users') > ) > } > ?> > > > class User extends AppModel { > > var $name = 'User'; > var $actsAs = array('Containable'); > > var $hasMany = array( > 'Activity' => array( > 'className' => 'Activity', > 'foreignKey' => 'doer_id', > 'conditions' => array( > 'Activity.doer_table' => 'users' > ), > 'dependent' => true > ); > } > ?> > > -- > Our newest site for the community: CakePHP Video > Tutorialshttp://tv.cakephp.org > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > others with their CakePHP related questions. > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
RE: How to properly use "conditions" in model associations
Personaly I never set any conditions in the relations (hasOne, hasMany ) all conditions are defined in the function since depending on why I am getting the data and for who conditions constantly change. You can say conditions Posts => 1 //active so you only by default display all active Post. but then when its time to get all users posts so they can edit their data you need to set condition where Post.id => $user_id. If you kept the regular condition you would only pull that users active posts not all. But I just developed from day 1 like this so also would be curious to see what others are doing in regards to the other params available for relations. Good question :) K -Original Message- From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of Eric Anderson Sent: Wednesday, March 02, 2011 3:57 PM To: CakePHP Subject: How to properly use "conditions" in model associations Hi everyone, I'm wondering what is the 'proper' or 'suggested' way of using "conditions" in model associations. I'm using an Activity model to log activities performed throughout my app. I then use this table to output activity feed / notifications style sections to users. The problem I'm having is that Cake throws a "column not found" error (I guess technically it's MySQL throwing the error). When running a query, Cake for some reason formulates the query so that MySQL is looking for columns from my Activity table inside of other tables. Do I need to specify "conditions" in both my User and Activity model, as shown below? When I remove the conditions from the Activity model, everything runs fine. array( 'className' => 'User', 'foreignKey' => 'doer_id', 'conditions' => array('Activity.doer_table' => 'users') ) } ?> array( 'className' => 'Activity', 'foreignKey' => 'doer_id', 'conditions' => array( 'Activity.doer_table' => 'users' ), 'dependent' => true ); } ?> -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
How to properly use "conditions" in model associations
Hi everyone, I'm wondering what is the 'proper' or 'suggested' way of using "conditions" in model associations. I'm using an Activity model to log activities performed throughout my app. I then use this table to output activity feed / notifications style sections to users. The problem I'm having is that Cake throws a "column not found" error (I guess technically it's MySQL throwing the error). When running a query, Cake for some reason formulates the query so that MySQL is looking for columns from my Activity table inside of other tables. Do I need to specify "conditions" in both my User and Activity model, as shown below? When I remove the conditions from the Activity model, everything runs fine. array( 'className' => 'User', 'foreignKey' => 'doer_id', 'conditions' => array('Activity.doer_table' => 'users') ) } ?> array( 'className' => 'Activity', 'foreignKey' => 'doer_id', 'conditions' => array( 'Activity.doer_table' => 'users' ), 'dependent' => true ); } ?> -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: can you bypass model associations in a find
On Wed, Jan 5, 2011 at 9:44 AM, roundrightfarm wrote: > Thanks for your help. Got it to work... but > can you please explain why this didn't work > > $orders = $this->Order->find('all', > array('conditions'=>array('Order.week_id'=>$week_id)), > array('contain' => array('Box' => array('Item'))) > ); You have too many arrays there. $orders = $this->Order->find( 'all', array( 'conditions'=>array('Order.week_id'=>$week_id), 'contain' => array('Box' => array('Item')) ) ); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: can you bypass model associations in a find
Thanks for your help. Got it to work... but can you please explain why this didn't work $orders = $this->Order->find('all', array('conditions'=>array('Order.week_id'=>$week_id)), array('contain' => array('Box' => array('Item'))) ); and I had to do this instead $this->Order->contain(array('Box' => array('Item'))); $orders = $this->Order->find('all', array('conditions'=>array('Order.week_id'=>$week_id)) ); On Jan 5, 5:18 am, Jeremy Burns | Class Outfit wrote: > The Containable behaviour is your very best > friend:http://book.cakephp.org/view/1323/Containable > > Jeremy Burns > Class Outfit > > jeremybu...@classoutfit.comhttp://www.classoutfit.com > > On 5 Jan 2011, at 13:10, roundrightfarm wrote: > > > I'm having to do a find('all') with recursive = 2 to get at the data I > > need in my array. Unfortunately using this level of recursion also > > pulls in a bunch of unneeded data, creating a monster array which is > > stretching the memory limits. > > > Is there some syntax (perhaps involving 'fields') that will either > > allow me to select only the associations I need for this particular > > array, or to leave out the association I don't need. I'm asssuming > > it would not be considered best practices to start messing with my > > model files just to get a smaller array in this one situation. > > > Thanks > > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others > > with their CakePHP related questions. > > > You received this message because you are subscribed to the Google Groups > > "CakePHP" group. > > To post to this group, send email to cake-php@googlegroups.com > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > athttp://groups.google.com/group/cake-php?hl=en > > Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: can you bypass model associations in a find
The Containable behaviour is your very best friend: http://book.cakephp.org/view/1323/Containable Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 5 Jan 2011, at 13:10, roundrightfarm wrote: > I'm having to do a find('all') with recursive = 2 to get at the data I > need in my array. Unfortunately using this level of recursion also > pulls in a bunch of unneeded data, creating a monster array which is > stretching the memory limits. > > Is there some syntax (perhaps involving 'fields') that will either > allow me to select only the associations I need for this particular > array, or to leave out the association I don't need. I'm asssuming > it would not be considered best practices to start messing with my > model files just to get a smaller array in this one situation. > > Thanks > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
can you bypass model associations in a find
I'm having to do a find('all') with recursive = 2 to get at the data I need in my array. Unfortunately using this level of recursion also pulls in a bunch of unneeded data, creating a monster array which is stretching the memory limits. Is there some syntax (perhaps involving 'fields') that will either allow me to select only the associations I need for this particular array, or to leave out the association I don't need. I'm asssuming it would not be considered best practices to start messing with my model files just to get a smaller array in this one situation. Thanks Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Newbie question - having trouble with baked model associations
See here: http://groups.google.com/group/cake-php/browse_thread/thread/7bfef9785d10d2d5 Jeremy Burns Class Outfit jeremybu...@classoutfit.com (t) +44 (0) 208 123 3822 (m) +44 (0) 7973 481949 Skype: jeremy_burns http://www.classoutfit.com On 15 Oct 2010, at 13:52, deafpanda wrote: > Hello, > > Sorry if this question is really stupid, I'm new to cake and I'm sure > I'm missing something obvious but Google isn't helping me... > > I'm following the tutorials in the cakephp book, and am on to the ACL > tutorial. I created all the tables and baked the models, controllers > and views but when I add a new user to the users table I do not see a > select box for the "group" field, but a normal text input box. There > are no links to related users on the group views pages, no links on > any of the pages to actions for related models. > > Help much appreciated, > > Will > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Newbie question - having trouble with baked model associations
See here: http://groups.google.com/group/cake-php/browse_thread/thread/7bfef9785d10d2d5 Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 15 Oct 2010, at 13:52, deafpanda wrote: > Hello, > > Sorry if this question is really stupid, I'm new to cake and I'm sure > I'm missing something obvious but Google isn't helping me... > > I'm following the tutorials in the cakephp book, and am on to the ACL > tutorial. I created all the tables and baked the models, controllers > and views but when I add a new user to the users table I do not see a > select box for the "group" field, but a normal text input box. There > are no links to related users on the group views pages, no links on > any of the pages to actions for related models. > > Help much appreciated, > > Will > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Newbie question - having trouble with baked model associations
Hello, Sorry if this question is really stupid, I'm new to cake and I'm sure I'm missing something obvious but Google isn't helping me... I'm following the tutorials in the cakephp book, and am on to the ACL tutorial. I created all the tables and baked the models, controllers and views but when I add a new user to the users table I do not see a select box for the "group" field, but a normal text input box. There are no links to related users on the group views pages, no links on any of the pages to actions for related models. Help much appreciated, Will Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Model Associations
Is there a best practice or rule of thumb to work from when defining model associations? It seems pretty cut and dry and there's not much that you can really mess up. I know this problem has been brought up here in the past but I'm still unable to find a solution after reviewing older threads. I'm getting the MAX_JOIN_SIZE error when attempting to login. "The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay" It's my User model that is triggering this error. There are about 10 $hasMany and 5 $hasOne assocs for this model. This really doesn't seem like too much does it? Is there an approximate number of relationships I should try no exceed? I still have more to add to it. I found an older thread that "claimed" ACL was to blame for this and the problem did go away for a while after I stopped using ACL but I really don't think ACL has anything to do with it. I'm guessing the I screwed something up with model associations but I'm not sure what or where the problem is. Any ideas where I may have gone wrong here? - Ed Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Model associations problem
The results are perfectly correct for the code you are running; you are finding all Trackers. Your code: $this->set('trackers', $this->User->Tracker->find('all')); ... is saying "go to the User model, then leap out to the Tracker model and bring me back all Trackers". To filter the search, pass in a condition: $this->set( 'trackers', $this->User->Tracker->find( 'all', array( 'conditions' = array( 'Tracker.user_id' => $userId // where $userId is 'this' user ) ) ) ); Or (in my opinion the better strategy) use the containable behaviour: http://book.cakephp.org/view/1323/Containable. Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 17 Jun 2010, at 00:43, ryanl wrote: > I'm in the process of creating my first web application with CakePHP, > however I've run into some problems. I'll just start with the code: > > > class User extends AppModel > { > public $name = 'User'; > public $belongsTo = 'Group'; > public $hasMany = array( > 'Tracker' => array( > 'className' => 'Tracker', > 'foreignKey' => 'user_id', > 'dependent' => true, > 'order' => 'Tracker.created DESC')); > > public $validate = array( > 'username' => 'alphaNumeric', > 'password' => 'notEmpty' > ); > } > > > class Tracker extends AppModel > { > public $name = 'Tracker'; > public $belongsTo = 'User'; > public $hasMany = array( > 'Log' => array( > 'className' => 'Log', > 'foreignKey' => 'tracker_id', > 'dependent' => true, > 'order' => 'Log.created DESC')); > > public $validate = array( > 'name' => 'alphaNumeric', > ); > } > > > class Log extends AppModel > { > public $name = 'Log'; > public $belongsTo = 'Tracker'; > public $validate = array(); > } > > > Basically you can see that each user has a tracker, and each tracker > has a log. The problem is that when I'm displaying trackers, I want to > display for each user ONLY the trackers that he or she owns. But > instead of doing that, it returns back all the trackers, including > ones that the user doesn't own. This is the code that I'm using: > > // inside of app/controllers/user_controller.php > > $this->set('trackers', $this->User->Tracker->find('all')); > $this->set('totalTrackers', $this->User->Tracker->find('count')); > > > Can someone help me solve the problem? > Thanks. > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Model associations problem
I'm in the process of creating my first web application with CakePHP, however I've run into some problems. I'll just start with the code: class User extends AppModel { public $name = 'User'; public $belongsTo = 'Group'; public $hasMany = array( 'Tracker' => array( 'className' => 'Tracker', 'foreignKey' => 'user_id', 'dependent' => true, 'order' => 'Tracker.created DESC')); public $validate = array( 'username' => 'alphaNumeric', 'password' => 'notEmpty' ); } class Tracker extends AppModel { public $name = 'Tracker'; public $belongsTo = 'User'; public $hasMany = array( 'Log' => array( 'className' => 'Log', 'foreignKey' => 'tracker_id', 'dependent' => true, 'order' => 'Log.created DESC')); public $validate = array( 'name' => 'alphaNumeric', ); } class Log extends AppModel { public $name = 'Log'; public $belongsTo = 'Tracker'; public $validate = array(); } Basically you can see that each user has a tracker, and each tracker has a log. The problem is that when I'm displaying trackers, I want to display for each user ONLY the trackers that he or she owns. But instead of doing that, it returns back all the trackers, including ones that the user doesn't own. This is the code that I'm using: // inside of app/controllers/user_controller.php $this->set('trackers', $this->User->Tracker->find('all')); $this->set('totalTrackers', $this->User->Tracker->find('count')); Can someone help me solve the problem? Thanks. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Cake caching model associations?
Oops, forgot that I also moved them into separate Plugins - fixed the problem now with a simple bit of common sense! Cheers! On May 12, 12:47 pm, "WoJo&Co" wrote: > Hi, > > Quick question about Cake and model associations. > > I had an association that worked fine: > > User hasOne UserAccount > fk: UserAccount.user_id > > UserAccount belongsTo Club > fk: UserAccount.club_id > > I have now changed this, so that > > User hasOne UserAccount > fk: UserAccount.user_id > > UserAccount belongsTo ClubAccount > fk: UserAccount.club_account_id > > Despite having been through every model, deleted the cache and set > debug to 2, Cake is still trying to join UserAccount with Club rather > than ClubAccount. I'm at my wits end trying to work out where this is > going wrong, even to the point of deleting and rewriting all of the > model files, but it still is looking for the old association. > > There are no relationships set up in the database (MyISAM rather than > InnoDB so that can't be the problem) and the database fields are > correct for the new arrangement. > > Anybody got any ideas? > > Cheers! > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with > their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Cake caching model associations?
Hi, Quick question about Cake and model associations. I had an association that worked fine: User hasOne UserAccount fk: UserAccount.user_id UserAccount belongsTo Club fk: UserAccount.club_id I have now changed this, so that User hasOne UserAccount fk: UserAccount.user_id UserAccount belongsTo ClubAccount fk: UserAccount.club_account_id Despite having been through every model, deleted the cache and set debug to 2, Cake is still trying to join UserAccount with Club rather than ClubAccount. I'm at my wits end trying to work out where this is going wrong, even to the point of deleting and rewriting all of the model files, but it still is looking for the old association. There are no relationships set up in the database (MyISAM rather than InnoDB so that can't be the problem) and the database fields are correct for the new arrangement. Anybody got any ideas? Cheers! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Model Associations - just feels wrong
Thanks for taking a look at that LunarDraco. At first, the database was going to be configured with no surrogate keys where there was a logical candidate key. At least for parent tables. Then I found out that cakephp does not support compound keys, so I had to abandon that plan. Also, I found out that it is generally better to do as you said with using separate program-use-only surrogate keys in this type of application. Apparently there are entire Vi/Emacs style debates of surrogates vs. logical data representation. At any rate, I have altered that in almost all cases, and with your recommendation may alter the rest. Thank you so much for your information about the zip codes; I actually had no idea that was the case. I will make the changes you recommend. I finally posted the full thing for people to see. Here is the full diagram so far, without the updated zip code set up. Keep in mind these are just representing the entities not the tables hence the ClassName instead of table_names. pdf: http://www.filedropper.com/mcidclassesrev6 dia: http://www.filedropper.com/mcidclassesrev6_1 On Mar 19, 12:21 pm, LunarDraco wrote: > The problem I see with your model is in your ZipLocation you have the > code set to a PK. > > The Problem: > It is often thought that a zipcode belongs to only one city. And that > a city can have many zipcodes. There are no such rules in the postal > system. > > One zip code could and often overlaps many city boundaries. Especially > in rural areas. > So your ZipLocation Table as it is defined could not have records like > the following without violating the PK: > 84087, Woods Cross, UT > 84087, West Bountiful, UT > > I see this design quite a bit and this is where you will run into > trouble. But probably not until you get quite a ways down the path of > development and start adding a bunch of data. > > You should follow the naming scheme for table names and special field > names like (id, [fkmodel]_id, name, description, created, modified) > this will help tremendously during the baking of your model as cake > will pick up all the appropriate hasOne, hasMany, belongsTo, etc. This > will also help in your building your forms for creating your dropdowns > and autofill text as if your models have a name field it is used in > the dropdown. I don't like to see user data stored in the PK. If you > need it to maintain uniqueness (which you don't want to in this case) > there are other ways to guarantee the user data is unique. PK and FK > should be for the data relations, and program use only. > I would review section 2.4 of the > manualhttp://book.cakephp.org/view/22/CakePHP-Conventions > which talks about all of the file naming, model and database, > controller and view conventions. > > Creating the tables as below allows you to have multiple cities in the > same zipcode and still maintain proper relations between the tables. > Your Model relations still remain as Location hasOne ZipLocation, > State hasMany ZipLocation, ZipLocations belongTo Locations, and > ZipLocations belongTo States. And your Form can display the proper > autofill selections when the user enters 84087 or any other zips that > might have multiple cities. > > -- > locations > -- > id (PK) > name > street1 > street 2 > zip_location_id (FK) > ... > > -- > zip_locations > -- > id (PK) > zipcode (indexed) > city > state_id (FK) > > -- > states > -- > id (PK) > code > name Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Model Associations - just feels wrong
The problem I see with your model is in your ZipLocation you have the code set to a PK. The Problem: It is often thought that a zipcode belongs to only one city. And that a city can have many zipcodes. There are no such rules in the postal system. One zip code could and often overlaps many city boundaries. Especially in rural areas. So your ZipLocation Table as it is defined could not have records like the following without violating the PK: 84087, Woods Cross, UT 84087, West Bountiful, UT I see this design quite a bit and this is where you will run into trouble. But probably not until you get quite a ways down the path of development and start adding a bunch of data. You should follow the naming scheme for table names and special field names like (id, [fkmodel]_id, name, description, created, modified) this will help tremendously during the baking of your model as cake will pick up all the appropriate hasOne, hasMany, belongsTo, etc. This will also help in your building your forms for creating your dropdowns and autofill text as if your models have a name field it is used in the dropdown. I don't like to see user data stored in the PK. If you need it to maintain uniqueness (which you don't want to in this case) there are other ways to guarantee the user data is unique. PK and FK should be for the data relations, and program use only. I would review section 2.4 of the manual http://book.cakephp.org/view/22/CakePHP-Conventions which talks about all of the file naming, model and database, controller and view conventions. Creating the tables as below allows you to have multiple cities in the same zipcode and still maintain proper relations between the tables. Your Model relations still remain as Location hasOne ZipLocation, State hasMany ZipLocation, ZipLocations belongTo Locations, and ZipLocations belongTo States. And your Form can display the proper autofill selections when the user enters 84087 or any other zips that might have multiple cities. -- locations -- id (PK) name street1 street 2 zip_location_id (FK) ... -- zip_locations -- id (PK) zipcode (indexed) city state_id (FK) -- states -- id (PK) code name Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Model Associations - just feels wrong
Antonio. I cannot post that; I have not built them yet. Before I build the models I wanted to make sure I had this class diagram whooped. It sounds like I correctly understood it, so I'm going to get the models built soon. When that happens I will post them here. In the mean time, if you'd like to see the entire diagram including the cake relationships, send me an email. I'd be happy to reply with the file. Thanks again for the assistance. On Mar 19, 6:13 am, Antônio Marco wrote: > Hi, TheKerk, morning! > > Can you post the models association's code here? > > Thanks. > > On 17 mar, 23:41, TheHerk wrote: > > > > > Here is a link to a screenshot of a class diagram I am working on, > > with noted model associations. There are several relationships in the > > diagram that feel wrong to me. The one in the diagram that illustrates > > this is between ZipLocation and State. In this case, state is > > enumerated in its own table. For some reason, to me, it seems strange > > that ZipLocation, the parent, is belongsTo. I keep thinking in my > > head, “Each ZipLocation has one associated State,” but it doesn't seem > > to work that way. There are several more instances of this dilemma, > > but they are just the same. > > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png > > > Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Model Associations - just feels wrong
Hi, TheKerk, morning! Can you post the models association's code here? Thanks. On 17 mar, 23:41, TheHerk wrote: > Here is a link to a screenshot of a class diagram I am working on, > with noted model associations. There are several relationships in the > diagram that feel wrong to me. The one in the diagram that illustrates > this is between ZipLocation and State. In this case, state is > enumerated in its own table. For some reason, to me, it seems strange > that ZipLocation, the parent, is belongsTo. I keep thinking in my > head, “Each ZipLocation has one associated State,” but it doesn't seem > to work that way. There are several more instances of this dilemma, > but they are just the same. > > http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png > > Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Model Associations - just feels wrong
This is how I see it: If your table has a column that is an ID to another table, this table is the child and the foreign table is the parent. So hence, child belongs to parent. And reversed its, parent has many child (or has one). On Mar 18, 7:02 pm, TheHerk wrote: > Phew. I was really hoping I would here this confirmation you two are > providing. I was on the fence and worried I'd come to understand it > wrong. Maybe serendipity, but I feel like I'm in good shape now. > Thanks a lot. > > On Mar 18, 7:14 pm, Miles J wrote: > > > The terms "hasOne", "hasMany", "belongsTo" and "HABTM" and just terms > > to make it easier to understand. It doesn't actually mean that one > > table belongs to another table 100% of the time, its just the easy way > > of saying. > > > But in your example, it seems like ZipLocation belongsTo State and > > State hasMany ZipLocation. > > > On Mar 18, 12:18 pm, TheHerk wrote: > > > > What you say makes sense. It makes sense to me that zip belong to > > > states because they really are the further breakdown. What I don't > > > understand is relations where child classes have many different > > > parents. I assume I am just over-thinking it, as per usual. Maybe it > > > really is as simple as it seems. Thank you for your help. > > > > If anybody is willing to look at the entire class diagram and tell me > > > if I'm headed down the wrong path or possible have it correct, please > > > do so. I'd be happy to email to you. > > > > On Mar 18, 9:00 am, John Andersen wrote: > > > > > If I understand you correctly, then you consider the ZipLocation to be > > > > the parent of the State? > > > > > My understanding of the situation is the reverse, one State may have > > > > one or more ZipLocations, so one ZipLocation belongs to one State. > > > > > So your diagram looks correct with regard to the relationship between > > > > ZipLocation and State :) > > > > Enjoy, > > > > John > > > > > On Mar 18, 4:41 am, TheHerk wrote: > > > > > > Here is a link to a screenshot of a class diagram I am working on, > > > > > with noted model associations. There are several relationships in the > > > > > diagram that feel wrong to me. The one in the diagram that illustrates > > > > > this is between ZipLocation and State. In this case, state is > > > > > enumerated in its own table. For some reason, to me, it seems strange > > > > > that ZipLocation, the parent, is belongsTo. I keep thinking in my > > > > > head, “Each ZipLocation has one associated State,” but it doesn't seem > > > > > to work that way. There are several more instances of this dilemma, > > > > > but they are just the same. > > > > > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png > > > > > > Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Model Associations - just feels wrong
Phew. I was really hoping I would here this confirmation you two are providing. I was on the fence and worried I'd come to understand it wrong. Maybe serendipity, but I feel like I'm in good shape now. Thanks a lot. On Mar 18, 7:14 pm, Miles J wrote: > The terms "hasOne", "hasMany", "belongsTo" and "HABTM" and just terms > to make it easier to understand. It doesn't actually mean that one > table belongs to another table 100% of the time, its just the easy way > of saying. > > But in your example, it seems like ZipLocation belongsTo State and > State hasMany ZipLocation. > > On Mar 18, 12:18 pm, TheHerk wrote: > > > > > What you say makes sense. It makes sense to me that zip belong to > > states because they really are the further breakdown. What I don't > > understand is relations where child classes have many different > > parents. I assume I am just over-thinking it, as per usual. Maybe it > > really is as simple as it seems. Thank you for your help. > > > If anybody is willing to look at the entire class diagram and tell me > > if I'm headed down the wrong path or possible have it correct, please > > do so. I'd be happy to email to you. > > > On Mar 18, 9:00 am, John Andersen wrote: > > > > If I understand you correctly, then you consider the ZipLocation to be > > > the parent of the State? > > > > My understanding of the situation is the reverse, one State may have > > > one or more ZipLocations, so one ZipLocation belongs to one State. > > > > So your diagram looks correct with regard to the relationship between > > > ZipLocation and State :) > > > Enjoy, > > > John > > > > On Mar 18, 4:41 am, TheHerk wrote: > > > > > Here is a link to a screenshot of a class diagram I am working on, > > > > with noted model associations. There are several relationships in the > > > > diagram that feel wrong to me. The one in the diagram that illustrates > > > > this is between ZipLocation and State. In this case, state is > > > > enumerated in its own table. For some reason, to me, it seems strange > > > > that ZipLocation, the parent, is belongsTo. I keep thinking in my > > > > head, “Each ZipLocation has one associated State,” but it doesn't seem > > > > to work that way. There are several more instances of this dilemma, > > > > but they are just the same. > > > > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png > > > > > Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Model Associations - just feels wrong
The terms "hasOne", "hasMany", "belongsTo" and "HABTM" and just terms to make it easier to understand. It doesn't actually mean that one table belongs to another table 100% of the time, its just the easy way of saying. But in your example, it seems like ZipLocation belongsTo State and State hasMany ZipLocation. On Mar 18, 12:18 pm, TheHerk wrote: > What you say makes sense. It makes sense to me that zip belong to > states because they really are the further breakdown. What I don't > understand is relations where child classes have many different > parents. I assume I am just over-thinking it, as per usual. Maybe it > really is as simple as it seems. Thank you for your help. > > If anybody is willing to look at the entire class diagram and tell me > if I'm headed down the wrong path or possible have it correct, please > do so. I'd be happy to email to you. > > On Mar 18, 9:00 am, John Andersen wrote: > > > If I understand you correctly, then you consider the ZipLocation to be > > the parent of the State? > > > My understanding of the situation is the reverse, one State may have > > one or more ZipLocations, so one ZipLocation belongs to one State. > > > So your diagram looks correct with regard to the relationship between > > ZipLocation and State :) > > Enjoy, > > John > > > On Mar 18, 4:41 am, TheHerk wrote: > > > > Here is a link to a screenshot of a class diagram I am working on, > > > with noted model associations. There are several relationships in the > > > diagram that feel wrong to me. The one in the diagram that illustrates > > > this is between ZipLocation and State. In this case, state is > > > enumerated in its own table. For some reason, to me, it seems strange > > > that ZipLocation, the parent, is belongsTo. I keep thinking in my > > > head, “Each ZipLocation has one associated State,” but it doesn't seem > > > to work that way. There are several more instances of this dilemma, > > > but they are just the same. > > > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png > > > > Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Model Associations - just feels wrong
What you say makes sense. It makes sense to me that zip belong to states because they really are the further breakdown. What I don't understand is relations where child classes have many different parents. I assume I am just over-thinking it, as per usual. Maybe it really is as simple as it seems. Thank you for your help. If anybody is willing to look at the entire class diagram and tell me if I'm headed down the wrong path or possible have it correct, please do so. I'd be happy to email to you. On Mar 18, 9:00 am, John Andersen wrote: > If I understand you correctly, then you consider the ZipLocation to be > the parent of the State? > > My understanding of the situation is the reverse, one State may have > one or more ZipLocations, so one ZipLocation belongs to one State. > > So your diagram looks correct with regard to the relationship between > ZipLocation and State :) > Enjoy, > John > > On Mar 18, 4:41 am, TheHerk wrote: > > > > > Here is a link to a screenshot of a class diagram I am working on, > > with noted model associations. There are several relationships in the > > diagram that feel wrong to me. The one in the diagram that illustrates > > this is between ZipLocation and State. In this case, state is > > enumerated in its own table. For some reason, to me, it seems strange > > that ZipLocation, the parent, is belongsTo. I keep thinking in my > > head, “Each ZipLocation has one associated State,” but it doesn't seem > > to work that way. There are several more instances of this dilemma, > > but they are just the same. > > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png > > > Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Model Associations - just feels wrong
If I understand you correctly, then you consider the ZipLocation to be the parent of the State? My understanding of the situation is the reverse, one State may have one or more ZipLocations, so one ZipLocation belongs to one State. So your diagram looks correct with regard to the relationship between ZipLocation and State :) Enjoy, John On Mar 18, 4:41 am, TheHerk wrote: > Here is a link to a screenshot of a class diagram I am working on, > with noted model associations. There are several relationships in the > diagram that feel wrong to me. The one in the diagram that illustrates > this is between ZipLocation and State. In this case, state is > enumerated in its own table. For some reason, to me, it seems strange > that ZipLocation, the parent, is belongsTo. I keep thinking in my > head, “Each ZipLocation has one associated State,” but it doesn't seem > to work that way. There are several more instances of this dilemma, > but they are just the same. > > http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png > > Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Model Associations - just feels wrong
Here is a link to a screenshot of a class diagram I am working on, with noted model associations. There are several relationships in the diagram that feel wrong to me. The one in the diagram that illustrates this is between ZipLocation and State. In this case, state is enumerated in its own table. For some reason, to me, it seems strange that ZipLocation, the parent, is belongsTo. I keep thinking in my head, “Each ZipLocation has one associated State,” but it doesn't seem to work that way. There are several more instances of this dilemma, but they are just the same. http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png Does this look remotely correct? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Model associations causing problems in behaviors
I have two associated models, Series (hasMany) and SeriesTitle (belongsTo) each use the Searchable behavior. While the association is active and I try to save to the SeriesTItle model, all behaviors break as for some reason $this->model contains the Series model rather than the SeriesTitle. This only affects SeriesTitle and removing the association fixes the problem. Errors: Notice: Undefined index: Series in D:...\app\models\behaviors \searchable.php on line 80 Warning: Invalid argument supplied for foreach() in D:...\app\models \behaviorssearchable.php on line 81 Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Model associations
Good evening, I am currently converting a game content management application over to CakePHP 1.3, and since this is my first try at baking I'd like to check if I am doing things the Cake way :-) The current model for a creature has four fields containing the ID of 3D textures. For each of these textures there is a separate model name texture_info to track stats like gender of bounding radius of a texture. If a I understand the Cake way of doing model associations, I would have to change the models to rather look like: [code] [/code] Thus I'd move the texture ID's currently living as columns inside the creature out, and only having texture_info models which have a column for creature_id linking them to the creature. Would that be the Cake way of model associations? With kind regards, Daniel S. Reichenbach Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Complex model associations, pagination and containable
I've managed to get it working. The answer was simple, yet not obvious. In order to get these deep level associations working you need to add the association in the first model. In my case that's Model1 or CourseResult. This is how: var $belongsTo = array( 'Course' => array( 'className' => 'Schools.Course', 'foreignKey' => 'course_id' ), 'School' => array( 'className' => 'Schools.School', 'foreignKey' => false, 'conditions' => 'Course.school_id = School.id' ), 'CourseLanguage' => array( 'className' => 'Schools.CourseLanguage', 'foreignKey' => false, 'conditions' => 'Course.course_language_id = CourseLanguage.id' ), 'CourseType' => array( 'className' => 'Schools.CourseType', 'foreignKey' => false, 'conditions' => 'Course.course_type_id = CourseType.id' ), 'CourseLevelMin' => array( 'className' => 'Schools.CourseLevel', 'foreignKey' => false, 'conditions' => 'Course.course_level_min = CourseLevelMin.order' ), 'CourseLevelMax' => array( 'className' => 'Schools.CourseLevel', 'foreignKey' => false, 'conditions' => 'Course.course_level_max = CourseLevelMax.order' ), 'CourseQualification' => array( 'className' => 'Schools.CourseQualification', 'foreignKey' => false, 'conditions' => 'Course.course_qualification_id = CourseQualification.id' ) ); Notice the foreignKey is false and the conditions are the ON clause in the level two associations. I hope that helps someone - I struggled with this problem for quite some time. On Sep 14, 2:22 am, brian wrote: > I see what you mean. My eyes glazed over. :-) > > How about posting the output of debug($this->paginate) (after you've > set the conditions)? > > On Sun, Sep 13, 2009 at 4:41 PM,martinp wrote: > > > It's quite complicated as I have to deal with some craziness in the > > form search form submission. I don't think this is the problem, but > > here's the function that sorts out the conditions: > > > private function setPreConditions() { > > $preConditions = $this->postConditions($this->data); > > unset($preConditions['Search.search']); > > $facilitiesConditions = array(); > > if(!empty($preConditions)) { > > foreach($preConditions as $key => $value) { > > if(empty($value)) { > > unset($preConditions[$key]); > > } else { > > if(substr($key, 0, 14) == > > 'SchoolFacility') { > > $facility_name = > > substr($key, 15); > > > > $facilitiesConditions[]['School.facilities LIKE ?'] = "% > > \"$facility_name\";s:1:\"1\";%"; > > unset($preConditions[$key]); > > } > > if($key == 'School.name') { > > $preConditions[]['or'] = > > array('LOWER(School.name) LIKE' => > > '%'.low($value).'%', 'LOWER(Course.name) LIKE' => '%'.low($value).'%', > > 'LOWER(CourseType.name) LIKE' => '%'.low($value).'%', 'LOWER > > (CourseQualification.name) LIKE' => '%'.low($value).'%', 'LOWER > > (CourseLevelMin.name) LIKE' => '%'.low($value).'%'); > > unset($preConditions[$key]); > > } > > if($key == 'Course.start_time') { > > switch($value) { > > case 'AM': > > > > $preConditions[]['or'] = array('Course.start_time <' => > > '12:00:00', 'Course.start_time' => null); > > break; > > case 'PM': > > > > $preConditions[]['or'] = array('Course.start_time >=' => > > '12:00:00', 'Course.start_time' => null); > > break; > > } > >
Model Associations on legacy tables with no primary keys
I have a legacy database and I am unfotunately unable to change the table structure. I have the following tables: CODE scheduled_models (no primary key set, but should be model_id) model_idint(11) auto_increment model_name varchar(15) ... and other fields and: CODE schedule_dates (again no primary key, but should have a separate id field) datedatetime model_name varchar(15) and: CODE scheduled_pics (again no primary key set, but should be pic_id) pic_id int(11) model_name varchar(15) and other fields I have a model for each and I am trying to link them together. The relationships should be (as best I understand) a scheduled_model belongsTo schedule_date, a schedule_date hasMany scheduled_model, a scheduled_model hasMany schedule_pic and a scheduled_pic belongsTo a scheduled_model. Nothing I have tried works and I think part of it is because the tables have no primary keys defined, and part because the foreign keys are a little odd. Currently, my models are as follows: PHP Code array ( foreignKey => false, conditions => array (’ScheduledDate.model_name’ => ‘ScheduledModel.model_name’))); var $hasMany = "ScheduledPic"; } ?> PHP Code array ( foreignKey => false, conditions => array (’ScheduledModel.model_name’ => ‘ScheduledDate.model_name’))); } ?> PHP Code Please help with getting these relationships defined. I am a beginner with cakePHP, and remember they are lagacy tables so cannot be changed. Thanks Maree --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Model associations problem
Hey folks, There is this problem I am facing at the moment. Not sure how to solve it. So, my Gallery var $hasOne = array( 'MainPhoto' => array( 'className' => 'Upload', 'foreignKey' => false, 'fields' => array('MainPhoto.filename'), 'conditions' => array('Gallery.main_photo_id = MainPhoto.id'), ) ); var $hasMany = array( 'GalleryPhoto' ); and my GalleryPhoto var $hasOne = array( 'GP' => array( 'className' => 'Upload', 'foreignKey' => false, 'conditions' => 'GalleryPhoto.photo_id = GP.id', 'fields' => array('GP.id', 'GP.filename'), ) ); However, when I do $this->Gallery->recursive = 2; $this->set('gallery', $this->Gallery->read(null, $id)); in my GalleriesController the result is not what I expected. Queries: SELECT `Gallery`.`id`, `Gallery`.`name`, `Gallery`.`main_photo_id`, `MainPhoto`.`filename` FROM `galleries` AS `Gallery` LEFT JOIN `uploads` AS `MainPhoto` ON (`Gallery`.`main_photo_id` = `MainPhoto`.`id`) WHERE `Gallery`.`id` = 7 LIMIT 1 SELECT `MainPhoto`.`filename` FROM `uploads` AS `MainPhoto` WHERE 1 = 1 SELECT `GalleryPhoto`.`id`, `GalleryPhoto`.`position`, `GalleryPhoto`.`gallery_id`, `GalleryPhoto`.`photo_id` FROM `gallery_photos` AS `GalleryPhoto` WHERE `GalleryPhoto`.`gallery_id` = (7) SELECT `GP`.`id`, `GP`.`filename` FROM `uploads` AS `GP` WHERE `GalleryPhoto`.`photo_id` = `GP`.`id` 1054: Unknown column 'GalleryPhoto.photo_id' in 'where clause' as far as you can see the last one is triggering a error, any ideas how do I left join the photo filename I need? Thanks in advance, Aivaras --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Complex model associations, pagination and containable
I see what you mean. My eyes glazed over. :-) How about posting the output of debug($this->paginate) (after you've set the conditions)? On Sun, Sep 13, 2009 at 4:41 PM, martinp wrote: > > It's quite complicated as I have to deal with some craziness in the > form search form submission. I don't think this is the problem, but > here's the function that sorts out the conditions: > > private function setPreConditions() { > $preConditions = $this->postConditions($this->data); > unset($preConditions['Search.search']); > $facilitiesConditions = array(); > if(!empty($preConditions)) { > foreach($preConditions as $key => $value) { > if(empty($value)) { > unset($preConditions[$key]); > } else { > if(substr($key, 0, 14) == > 'SchoolFacility') { > $facility_name = substr($key, > 15); > > $facilitiesConditions[]['School.facilities LIKE ?'] = "% > \"$facility_name\";s:1:\"1\";%"; > unset($preConditions[$key]); > } > if($key == 'School.name') { > $preConditions[]['or'] = > array('LOWER(School.name) LIKE' => > '%'.low($value).'%', 'LOWER(Course.name) LIKE' => '%'.low($value).'%', > 'LOWER(CourseType.name) LIKE' => '%'.low($value).'%', 'LOWER > (CourseQualification.name) LIKE' => '%'.low($value).'%', 'LOWER > (CourseLevelMin.name) LIKE' => '%'.low($value).'%'); > unset($preConditions[$key]); > } > if($key == 'Course.start_time') { > switch($value) { > case 'AM': > > $preConditions[]['or'] = array('Course.start_time <' => > '12:00:00', 'Course.start_time' => null); > break; > case 'PM': > > $preConditions[]['or'] = array('Course.start_time >=' => > '12:00:00', 'Course.start_time' => null); > break; > } > unset($preConditions[$key]); > } > if($key == 'Course.max_class_size') { > > $preConditions['Course.max_class_size <='] = $value; > unset($preConditions[$key]); > } > if($key == 'Course.course_level_min') { > $preConditions[]['or'] = > array('CourseLevelMin.order <=' => > $value, 'Course.course_level_min' => null); > unset($preConditions[$key]); > } > if($key == 'Student.age') { > $preConditions[]['or'] = > array('Course.minimum_age <=' => > $value, 'Course.minimum_age' => null); > $preConditions[]['or'] = > array('Course.maximum_age >=' => > $value, 'Course.maximum_age' => null); > $preConditions[]['or'] = > array('Accommodation.minimum_age <=' => > $value, 'Accommodation.minimum_age' => null); > $preConditions[]['or'] = > array('Accommodation.maximum_age >=' => > $value, 'Accommodation.maximum_age' => null); > unset($preConditions[$key]); > } > if($key == 'Course.lessons_per_week') { > switch($value) { > case 1: > > $preConditions['Course.lessons_per_week <='] = 10; > break; > case 2: > > $preConditions['Course.lessons_per_week >='] = 10; > > $preConditions['Course.lessons_per_wee
Re: Complex model associations, pagination and containable
It's quite complicated as I have to deal with some craziness in the form search form submission. I don't think this is the problem, but here's the function that sorts out the conditions: private function setPreConditions() { $preConditions = $this->postConditions($this->data); unset($preConditions['Search.search']); $facilitiesConditions = array(); if(!empty($preConditions)) { foreach($preConditions as $key => $value) { if(empty($value)) { unset($preConditions[$key]); } else { if(substr($key, 0, 14) == 'SchoolFacility') { $facility_name = substr($key, 15); $facilitiesConditions[]['School.facilities LIKE ?'] = "% \"$facility_name\";s:1:\"1\";%"; unset($preConditions[$key]); } if($key == 'School.name') { $preConditions[]['or'] = array('LOWER(School.name) LIKE' => '%'.low($value).'%', 'LOWER(Course.name) LIKE' => '%'.low($value).'%', 'LOWER(CourseType.name) LIKE' => '%'.low($value).'%', 'LOWER (CourseQualification.name) LIKE' => '%'.low($value).'%', 'LOWER (CourseLevelMin.name) LIKE' => '%'.low($value).'%'); unset($preConditions[$key]); } if($key == 'Course.start_time') { switch($value) { case 'AM': $preConditions[]['or'] = array('Course.start_time <' => '12:00:00', 'Course.start_time' => null); break; case 'PM': $preConditions[]['or'] = array('Course.start_time >=' => '12:00:00', 'Course.start_time' => null); break; } unset($preConditions[$key]); } if($key == 'Course.max_class_size') { $preConditions['Course.max_class_size <='] = $value; unset($preConditions[$key]); } if($key == 'Course.course_level_min') { $preConditions[]['or'] = array('CourseLevelMin.order <=' => $value, 'Course.course_level_min' => null); unset($preConditions[$key]); } if($key == 'Student.age') { $preConditions[]['or'] = array('Course.minimum_age <=' => $value, 'Course.minimum_age' => null); $preConditions[]['or'] = array('Course.maximum_age >=' => $value, 'Course.maximum_age' => null); $preConditions[]['or'] = array('Accommodation.minimum_age <=' => $value, 'Accommodation.minimum_age' => null); $preConditions[]['or'] = array('Accommodation.maximum_age >=' => $value, 'Accommodation.maximum_age' => null); unset($preConditions[$key]); } if($key == 'Course.lessons_per_week') { switch($value) { case 1: $preConditions['Course.lessons_per_week <='] = 10; break; case 2: $preConditions['Course.lessons_per_week >='] = 10; $preConditions['Course.lessons_per_week <='] = 15; break; case 3: $preConditions['Course.lessons_per_week >'] = 15;
Re: Complex model associations, pagination and containable
I missed Miles's post, also. I, too, think your $conditions looks strange. Can you post the actual code (not debug output)? On Fri, Sep 11, 2009 at 11:57 AM, martinp wrote: > > Hello > > Thanks for your replies. I thought I was watching this topic, but > wasn't aware that the discussion had continued without me! > > Brian - I think you've hit the nail on the head regarding my > containment problem, but I still don't have it working. > Miles J - I assure you they are all belongsTo associations. What is > wrong with my conditions array? > > I've stripped it back a bit to try and get the 'School' association > working first. Here's what I have: > > $this->paginate['CourseResult'] = array( > 'fields' => array( > 'CourseResult.id', > 'CourseResult.course_id', > 'CourseResult.no_of_weeks', > 'CourseResult.year', > 'CourseResult.price' > ), > 'contain' => array( > 'Course' => array( > 'fields' => array( > 'Course.id', > 'Course.school_id', > 'Course.name', > 'Course.course_language_id', > 'Course.course_type_id', > > 'Course.course_qualification_id', > 'Course.course_level_min', > 'Course.course_level_max', > 'Course.published', > 'Course.deleted' > ), > 'School' => array( > 'fields' => array( > 'School.id', > 'School.name', > 'School.city', > 'School.country_id' > ) > ) > ) > ), > 'conditions' => $conditions > ); > $rows = $this->paginate('CourseResult'); > > Working with the same conditions as above and with the same result. > > On Sep 4, 9:31 pm, Miles J wrote: >> Correct me if im wrong, but are you allowed to use $conditions the way >> he is? On top of that, I feel like were not seeing all the queries, >> all of those associations cant be belongsTo. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Complex model associations, pagination and containable
Hello Thanks for your replies. I thought I was watching this topic, but wasn't aware that the discussion had continued without me! Brian - I think you've hit the nail on the head regarding my containment problem, but I still don't have it working. Miles J - I assure you they are all belongsTo associations. What is wrong with my conditions array? I've stripped it back a bit to try and get the 'School' association working first. Here's what I have: $this->paginate['CourseResult'] = array( 'fields' => array( 'CourseResult.id', 'CourseResult.course_id', 'CourseResult.no_of_weeks', 'CourseResult.year', 'CourseResult.price' ), 'contain' => array( 'Course' => array( 'fields' => array( 'Course.id', 'Course.school_id', 'Course.name', 'Course.course_language_id', 'Course.course_type_id', 'Course.course_qualification_id', 'Course.course_level_min', 'Course.course_level_max', 'Course.published', 'Course.deleted' ), 'School' => array( 'fields' => array( 'School.id', 'School.name', 'School.city', 'School.country_id' ) ) ) ), 'conditions' => $conditions ); $rows = $this->paginate('CourseResult'); Working with the same conditions as above and with the same result. On Sep 4, 9:31 pm, Miles J wrote: > Correct me if im wrong, but are you allowed to use $conditions the way > he is? On top of that, I feel like were not seeing all the queries, > all of those associations cant be belongsTo. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Complex model associations, pagination and containable
Correct me if im wrong, but are you allowed to use $conditions the way he is? On top of that, I feel like were not seeing all the queries, all of those associations cant be belongsTo. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Complex model associations, pagination and containable
On Fri, Sep 4, 2009 at 2:16 PM, Miles J wrote: > > But its in the where clause, so hes supplying it himself. > > LEFT JOIN `courses` AS `Course` ON > (`CourseResult`.`course_id` = `Course`.`id`) WHERE > `Course`.`course_type_id` = 1 AND `School`.`city` = 'London' AND > `School`.`country_id` = '225' AND ((`CourseLevelMin`.`order` <= '1') > OR (`Course`.`course_level_min` IS NULL)) AND `Course`.`published` = 1 > AND `Course`.`deleted` = 0 LIMIT 20 There's no join on schools in that query. The DB doesn't know what "School" is because it hasn't been aliased to schools table ... because there is no join on schools table. The DB doesn't care about "city" because "School" is unknown but it specifies "School.city" in the error msg because that's what's in the query. It *looks* like the problem is *only* that the "city" column is unknown but, in fact, it's "School.city" that the DB doesn't understand. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Complex model associations, pagination and containable
But its in the where clause, so hes supplying it himself. LEFT JOIN `courses` AS `Course` ON (`CourseResult`.`course_id` = `Course`.`id`) WHERE `Course`.`course_type_id` = 1 AND `School`.`city` = 'London' AND `School`.`country_id` = '225' AND ((`CourseLevelMin`.`order` <= '1') OR (`Course`.`course_level_min` IS NULL)) AND `Course`.`published` = 1 AND `Course`.`deleted` = 0 LIMIT 20 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Complex model associations, pagination and containable
On Fri, Sep 4, 2009 at 11:55 AM, Miles J wrote: > > No its not. > > Error: 1054: Unknown column 'School.city' in 'where clause' > > That means you dont have a column named city on your school table/ > model, thats not caused by the containment. It *appears* that way, yes. But remember that "School" is an alias. There is no join on schools table here: FROM `course_results` AS `CourseResult` LEFT JOIN `courses` AS `Course` ON (`CourseResult`.`course_id` = `Course`.`id`) WHERE `Course`.`course_type_id` = 1 AND `School`.`city` = 'London' AND `School`.`country_id` = '225' AND ((`CourseLevelMin`.`order` <= '1') OR (`Course`.`course_level_min` IS NULL)) AND `Course`.`published` = 1 AND `Course`.`deleted` = 0 LIMIT 20 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Complex model associations, pagination and containable
No its not. Error: 1054: Unknown column 'School.city' in 'where clause' That means you dont have a column named city on your school table/ model, thats not caused by the containment. On Sep 4, 1:12 am, martinp wrote: > Haven't I got MySQL errors because my model's aren't being contained? > > On Sep 4, 3:54 am, Miles J wrote: > > > Well there you go, it aint containing cause your MySQL fails. Try > > fixing that first. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---