that's how i do it.

whenever i'm saving a model I know that whatever is in the data array
at the time will be what is saved. so, how you get the foreign key in
there doesn't really matter (at the view or in the controller) as long
as it is in there it will be saved to the DB.

does that answer your question? i don't know if there is a better
practice or preferred method of doing this but generally i run with
the foreign id in the view just how you've done it.

On 25/09/06, Andrew <[EMAIL PROTECTED]> wrote:
>
> OK I got bake working using the hack described here:
> http://www.soledadpenades.com/category/cakephp/
>
> And even with a baked version, I still have the problem.  I can't
> imagine this is such a hard thing to overcome, can someone please help
> me?  I'm pulling my hair out, I've been stuck at this point for two
> weeks!
>
> I noticed that I can insert the foreign id with this line in the view
> form:
> echo $html->hidden('Option/decision_id',
> 'value="'.$decision['Decision']['id'].'"');
>
> But that really seems like a hack.  Please?  Someone?  I've included
> the original post below.
>
> Hi folks,
>
> I'm at my wit's end trying to figure out how to create a new related
> record... should be easy for you seasoned pros.  I'll be as detailed as
> possible.
>
> I have two tables: decisions, and options.  One decision has many
> options.  Here's the decision model code:
>
> <?php
>
> class Decision extends AppModel
> {
>     var $name = 'Decision';
>         var $hasMany = 'Option';
>
> }
>
> ?>
>
> and the Option model is similar.
>
> Here is the decisions_controller:
>
> <?php
>
> class DecisionsController extends AppController
> {
>         var $name = 'Decisions';
>         var $helpers = array('Time');
>
>         function index()
>         {
>                 $this->set('decisions', $this->Decision->findAll());
>         }
>
>         function view($id = null)
>         {
>                 $this->Decision->id = $id;
>                 $this->set('decision', $this->Decision->read());
>         }
>
>         function addOption()
>         {
>                 if(!empty($this->data))
>                 {
>                         debug($this->data);
>                         $this->Decision->Option->save($this->data);
>
>                         $this->flash('Option Added', '/decisions');
>                 }
>         }
>
> }
>
> ?>
>
> When the user is at decisions/view, they see the text of the decision
> and have the ability to add an option on a form.  Here's the view for
> decisions/view:
>
> <?php
> echo '<h1>'.$decision['Decision']['title'].'</h1>'
> ?>
> <h3>Options</h3>
> <?php
>         debug($decision);
> ?>
> <h2>Add a new option</h2>
> <form method="post" action="<?php echo
> $html->url('/decisions/addOption/')?>">
> <?php
>         echo $html->input('Option/option');
>         echo $html->submit('Save');
> ?>
>
> When the user submits this form, it does add a record to the options
> table.  Here's the SQL statement it outputs:
>
> INSERT INTO `options` (`option`,`created`,`modified`) VALUES
> ('test','2006-09-21 07:22:29','2006-09-21 07:22:29')
>
> For some reason, however, it isn't inserting a foreign key into the
> option.  There is a decision_id field in the options table that I would
> think it should populate.
>
> Note that if I turn on scaffolding, everything works fine, so I think
> my table structures, etc. conform to the cake conventions.
>
> Anyone see what I'm missing?  Something in the view, perhaps?
>
> Thanks in advance,
>
> Andrew
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to