I see how you think that might work; but Cake doesn't know you want that behaviour out of the box.
You would need to adjust your Question Add
method, or create a new one:
Example code:
// action: tests/view/1 (viewing test 1, and all related questions)
// create a link containing the ID of the current test as a param
<?php echo $this->Html->link('Add Question to Test',
array('controller'=>'questions',
'action' => 'add_question',
$test['Test']['id'])
);
?>
So - assuming you have access to id
of the current test
, you can pass it as a parameter to your questions
controller (there are several ways to do this).
Then:
// view - questions/add_question/1
<h1>Adding A Question to Test 1</h1>
<?php
// create your add question form
$this->Form->input('test_id', array('type'=>'hidden',
'value' => $this->params['pass'][0]));
// create a hidden field with the value of the first passed param (the test id)
then in your controller, the test_id
is already set, so when you save the question, it is saved with the appropriate test_id