[eluser]Dennis Rasmussen[/eluser]
This is just ridiculous...
Could someone explain to me what kind of method they would use to do such a simple thing (yet so complicated with Datamapper) as being able to create/edit a row in table_1 while creating/updating relations to table_2 with a many:many relation?
Code:
table_1
id - name
table_2
id - title
table_3 (join table)
id(1) - id(2)
So basically I'm having:
- A controller to handle the create/update behavior
- 2 models for the tables, both related to each other as many:many
- A view with a formula with name input for table_1 and a multiselect element having options from table_2
When I submit I'd like the following to happen:
- Create a new row in table_1
- Create rows in table_3 with relations between the new row in table_1 and the multiselected rows in table_2
All of this can easily be done without Datamapper, so why can't I with Datamapper?
Sure I could just do the following, but that seriously can't be healthy for the server with all these objects being created for each relation?
Code:
foreach($this->input->post('multiselect') as $key => $id)
{
$t2 = new Table_2($id);
$t1->save($t2);
}
Note that the variable names are changed for simplicity.