Re: how do I handle foreign keys??
Ok, it works now. I guess $uses is what I was missing. Thanks On Jun 20, 8:08 pm, "Chris Hartjes" <[EMAIL PROTECTED]> wrote: > On Fri, Jun 20, 2008 at 10:33 PM, Turnquist, Jonah <[EMAIL PROTECTED]> wrote: > > > Eh, it did not work. And I read those pages, it does not seem to tell > > me. Do I need to do this manually using find() to find all the > > categories and than pass those to the input through 'options' or will > > cake do some magic because of my $belongsTo definition? Also, if I do > > it manually, how would I call the Categories modal from the Scripts > > controller? This obviously did not work in my Scripts controller: > > $this->Category->find('all', array('recursive' => -1)); > > It looks to me like you're trying to generate a list of things for > your form. If so, try this from your scripts controller: > > $this->Entry->Category->recursive = -1; > $results = $this->Entry->Category->find('list'); > > Make sure that you've set the $uses variable in your Scripts > controller to tell it you want to use Entry. > > class ScriptsController extends AppController { > var $uses = array('Entry', ...) > ... > > } > > Hope that helps. > > -- > Chris Hartjes > Internet Loudmouth > Motto for 2008: "Moving from herding elephants to handling snakes..." > @TheKeyBoard:http://www.littlehart.net/atthekeyboard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how do I handle foreign keys??
On Fri, Jun 20, 2008 at 10:33 PM, Turnquist, Jonah <[EMAIL PROTECTED]> wrote: > > Eh, it did not work. And I read those pages, it does not seem to tell > me. Do I need to do this manually using find() to find all the > categories and than pass those to the input through 'options' or will > cake do some magic because of my $belongsTo definition? Also, if I do > it manually, how would I call the Categories modal from the Scripts > controller? This obviously did not work in my Scripts controller: > $this->Category->find('all', array('recursive' => -1)); It looks to me like you're trying to generate a list of things for your form. If so, try this from your scripts controller: $this->Entry->Category->recursive = -1; $results = $this->Entry->Category->find('list'); Make sure that you've set the $uses variable in your Scripts controller to tell it you want to use Entry. class ScriptsController extends AppController { var $uses = array('Entry', ...) ... } Hope that helps. -- Chris Hartjes Internet Loudmouth Motto for 2008: "Moving from herding elephants to handling snakes..." @TheKeyBoard: http://www.littlehart.net/atthekeyboard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how do I handle foreign keys??
Eh, it did not work. And I read those pages, it does not seem to tell me. Do I need to do this manually using find() to find all the categories and than pass those to the input through 'options' or will cake do some magic because of my $belongsTo definition? Also, if I do it manually, how would I call the Categories modal from the Scripts controller? This obviously did not work in my Scripts controller: $this->Category->find('all', array('recursive' => -1)); Thanks, Jonah On Jun 20, 12:40 am, "dr. Hannibal Lecter" <[EMAIL PROTECTED]> wrote: > Try using $form->select('Entry.category_id', ...) > > http://manual.cakephp.org/view/182/formhttp://api.cakephp.org/class_form_helper.html#5171e675468c9665db0653c... > > Any if you get stuck, read this one too: > > http://groups.google.com/group/cake-php/browse_thread/thread/fb6b71db... > > On Jun 20, 2:35 am, "Turnquist, Jonah" <[EMAIL PROTECTED]> wrote: > > > Also i should note that right now it's just showing a text box, no > > drop down --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how do I handle foreign keys??
Make sure your associations aren't backwards. Read http://book.cakephp.org/view/66/models#associations-78 , compare foreignKey for hasOne and belongsTo. On 20 Jun 2008, at 09:34, Turnquist, Jonah wrote: > > I have a 'entries' table and a 'categories' table. I am creating an > 'add' page to add a new entry, and I want to be able to select the > category that the entry goes into. > > View: > > Add Entry > echo $form->create('Entry'); > echo $form->input('category_id'); > echo $form->end('Submit'); > ?> > > Model: > > class Entry extends AppModel > { > var $hasOne = 'Category'; > > var $validate = array( > ); > > } > > ?> > > Category modal: > > class Category extends AppModel > { > > var $validate = array( > ); > > } > > I want the add page to show a drop down menu of all the availiable > categories in the categories table, what am i doing wrong? > > Thanks, > Jonah > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how do I handle foreign keys??
Try using $form->select('Entry.category_id', ...) http://manual.cakephp.org/view/182/form http://api.cakephp.org/class_form_helper.html#5171e675468c9665db0653c165b6c89c Any if you get stuck, read this one too: http://groups.google.com/group/cake-php/browse_thread/thread/fb6b71db2de8392d/eec7b739313c283f On Jun 20, 2:35 am, "Turnquist, Jonah" <[EMAIL PROTECTED]> wrote: > Also i should note that right now it's just showing a text box, no > drop down --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how do I handle foreign keys??
Also i should note that right now it's just showing a text box, no drop down --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
how do I handle foreign keys??
I have a 'entries' table and a 'categories' table. I am creating an 'add' page to add a new entry, and I want to be able to select the category that the entry goes into. View: Add Entry create('Entry'); echo $form->input('category_id'); echo $form->end('Submit'); ?> Model: Category modal: http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---