fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
151 stars 95 forks source link

Duplicate Entries in ORM many-many relation #405

Closed AdelWehbi closed 7 years ago

AdelWehbi commented 7 years ago

Something along these lines causes duplicate entries:

Model_One and Model_Two have a many many relation successfully set up.

$obj1 = Model_Onet::find($one_ID);
$obj2 = Model_Twot::find($obj1_ID);
$obj1->twos[] = $obj;
$obj1->save();
//so far so good.
$obj3 = Model_Two::find($obj3_ID);
$obj1->twos[] = $obj3;
$obj1->save();
//here, in the many many relation table, we find that $obj2 was saved again, along with $obj3. (twice $obj2, once $obj3)

//if we continue...
$obj4 = Model_Two::find($obj4_ID);
$obj1->twos[] = $obj4;
$obj1->save();
//now in the many many relation table, $obj2 is repeated 3 times, $obj3 twice, and $obj4 once.

doesn't the orm check whether the object was already saved?

WanWizard commented 7 years ago

I can confirm this bug. This used to work fine, so I assume a recent change broke it, I'll see if I can find it.