Re: Database associations
This should work: class Contact extends AppModel { var $hasMany = array( 'Call' => array( 'foreignKey' => false, 'conditions' => array( 'Call.number = Contact.number' ) ) ); } hth grigri On Jul 9, 12:06 am, Justin Beeler wrote: > I'm working with two tables: Contacts and Calls. > > I want to join the calls with the contacts on a field called > "number" (the phone number). Is there not a way in cake to manually > join tables and not have it join on a field like [model]_id ? > > If you need any further details, let me know. 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: Database associations
You can use the join statement: http://book.cakephp.org/view/1047/Joining-tables )although it's not ideal). Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 9 Jul 2010, at 00:06, Justin Beeler wrote: > I'm working with two tables: Contacts and Calls. > > I want to join the calls with the contacts on a field called > "number" (the phone number). Is there not a way in cake to manually > join tables and not have it join on a field like [model]_id ? > > If you need any further details, let me know. > > 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
Database associations
I'm working with two tables: Contacts and Calls. I want to join the calls with the contacts on a field called "number" (the phone number). Is there not a way in cake to manually join tables and not have it join on a field like [model]_id ? If you need any further details, let me know. 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: Database Associations Not Linking Up
I am using scaffolding, so there is no code used there... I have figured this out, though. I needed to define an action to tell the action to find all records and their recursive items. Here is the action I defined: function index(){ $this->Profile->recursive = 1; $profiles = $this->Profile->find('all'); $this->set('profiles',$profiles); } I then had to make a view for index and used the following code: Name Address Phone Numbers Emails Actions '; } ?> On May 13, 8:12 pm, andy wrote: > Can you post the code you are using to retrieve and display the data? > > On May 12, 3:17 pm, Site Reference wrote: > > > Hey all, > > > I apologize if this is a bit of a newbie question, but I am having > > trouble getting my database associations to link up...here is what I > > have: > > > MySQL Tables > > > CREATE TABLE phones ( > > id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, > > profile_id INTEGER UNSIGNED NULL, > > phone VARCHAR(255) NULL, > > created INTEGER UNSIGNED NULL, > > modified INTEGER UNSIGNED NULL, > > PRIMARY KEY(id) > > ); > > > CREATE TABLE profiles ( > > id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, > > name VARCHAR(255) NULL, > > main_address VARCHAR(255) NULL, > > created INTEGER UNSIGNED NULL, > > modified INTEGER UNSIGNED NULL, > > PRIMARY KEY(id) > > ); > > > Here are my models: > > > > class Phone extends AppModel { > > var $name = 'Phone'; > > var $belongsTo = 'Profile';} > > > ?> > > > > class Profile extends AppModel { > > var $name = 'Profile'; > > var $hasMany = 'Phone';} > > > ?> > > > I am using scaffolding for the controllers. Cake seems to see the > > relationship, but is not listing phones in the profiles. Is there > > anyway that I can do this, or is the fact that there are many phone > > numbers to a profile a problem? --~--~-~--~~~---~--~~ 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: Database Associations Not Linking Up
Can you post the code you are using to retrieve and display the data? On May 12, 3:17 pm, Site Reference wrote: > Hey all, > > I apologize if this is a bit of a newbie question, but I am having > trouble getting my database associations to link up...here is what I > have: > > MySQL Tables > > CREATE TABLE phones ( > id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, > profile_id INTEGER UNSIGNED NULL, > phone VARCHAR(255) NULL, > created INTEGER UNSIGNED NULL, > modified INTEGER UNSIGNED NULL, > PRIMARY KEY(id) > ); > > CREATE TABLE profiles ( > id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, > name VARCHAR(255) NULL, > main_address VARCHAR(255) NULL, > created INTEGER UNSIGNED NULL, > modified INTEGER UNSIGNED NULL, > PRIMARY KEY(id) > ); > > Here are my models: > > class Phone extends AppModel { > var $name = 'Phone'; > var $belongsTo = 'Profile';} > > ?> > > class Profile extends AppModel { > var $name = 'Profile'; > var $hasMany = 'Phone';} > > ?> > > I am using scaffolding for the controllers. Cake seems to see the > relationship, but is not listing phones in the profiles. Is there > anyway that I can do this, or is the fact that there are many phone > numbers to a profile a problem? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Database Associations Not Linking Up
Hey all, I apologize if this is a bit of a newbie question, but I am having trouble getting my database associations to link up...here is what I have: MySQL Tables CREATE TABLE phones ( id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, profile_id INTEGER UNSIGNED NULL, phone VARCHAR(255) NULL, created INTEGER UNSIGNED NULL, modified INTEGER UNSIGNED NULL, PRIMARY KEY(id) ); CREATE TABLE profiles ( id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(255) NULL, main_address VARCHAR(255) NULL, created INTEGER UNSIGNED NULL, modified INTEGER UNSIGNED NULL, PRIMARY KEY(id) ); Here are my models: I am using scaffolding for the controllers. Cake seems to see the relationship, but is not listing phones in the profiles. Is there anyway that I can do this, or is the fact that there are many phone numbers to a profile a problem? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---