I have two CakePHP models, Tests and Questions, where a Test has many questions, and a Question only has one test.
Neither this code:
echo $form->create("Question", array('action' => 'add'));
echo $form->input("text");
echo $form->input("Test.id", array( 'value' => $test['Test']['id'] , 'type' => 'hidden') );
echo $form->end("Add");
Nor:
echo $form->create("Question", array('action' => 'add'));
echo $form->input("text");
echo $form->input("Question.Test.id", array( 'value' => $test['Test']['id'] , 'type' => 'hidden') );
echo $form->end("Add");
associates the new question with a test (but does create it in the database).
$test[‘Test’][‘id’] does produce a correct output of ID.
Assistance appreciated.
You should associate (if you haven’t done it yet) the two models with
hasOneandhasManyassociations and doing so creating in the tablequestionsa column calledtest_id(that’s named foreignKey).The form of the question then becomes: