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->hidden('Option/decision_id',  55);
        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 [email protected]
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