j4mie/paris

Saving associated models.

fluxynet opened this issue · 1 comments

Suppose we have two entities Classroom and Student, with the following relationship:

    Classroom --< Student

The following code will successfully yield an array of Student instances associated with a Classroom instance.

$students = $classroom->students()->get_many();

However the following will not work:

$classroom->students = array($student_1, $student_2);
$classroom->save();

Instead, the following needs to be done:

$student_1->classroom_id = $classroom->id;
$student_2->classroom_id = $classroom->id;
$student_1->save();
$student_2->save();

This defeats the purpose of an ORM, doesn't it? Or does Paris ORM has a way to handle that which I may have missed?

It's not in the design of Paris or a requirement of an ORM.