Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM: Saving ids on relationship table
#1

[eluser]pfreitas[/eluser]
I've a employees, services and a employees_services table where I store the services one employee execute with their id and service id. I'm having trouble to save/update the services one employee execute...

Code:
// ...
$employee = new Employee;
$employee->from_array($this->input->post(null, true), array(
    // ... fields ...
));
$service = new Service;
    ->select('id')
    ->where_in('id', $this->input->post('services')) // ids from select-box
    ->get();
$employee->save(array('service' => $service->all));
This code is saving services, but if I try to deselect any option, it doesn't get deleted... I don't know where I'm doing wrong, what I've to do to insert/delete services based on select-box selection?

Thank you in advance!
#2

[eluser]WanWizard[/eluser]
You'll have to delete them.

Datamapper doesn't know what relations are already present with this code, nor what you indent to do with them.

This code only creates or updates the relation between the employee and the services listed in service->all, it doesn't delete anything. You'll have to do that yourself.




Theme © iAndrew 2016 - Forum software by © MyBB