yossi
yossi

Reputation: 3164

cakePHP single form, two tables, multiple records

There are two tables:
poducts [id, name, etc..] and specs [id, product_id, spec_name, spec_value],
I'm using a form to edit the product (/products/edit/332 for example)
In the form i wan to add (it's associated and i can access it in the view) the specs. which are a list of records from the specs table.

is it possible to create the specs as inputs in the same form? also, i would like to enable the feature of "add new spec".

thanks

Upvotes: 0

Views: 2253

Answers (1)

Paulo Rodrigues
Paulo Rodrigues

Reputation: 5303

For saving related model data, you can use saveAll:

$this->Product->saveAll($this->request->data);

And your inputs in Product form:

echo $form->input('Spec.0.spec_name');
echo $form->input('Spec.0.spec_value');

If you need more inputs, just increase the 0 value.

More information: http://book.cakephp.org/2.0/en/models/saving-your-data.html

Upvotes: 2

Related Questions