fuelphp-storage / fuelphp

FuelPHP framework
http://fuelphp.com
MIT License
274 stars 57 forks source link

ORM Many-Many Duplicates #77

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?

emlynwest commented 7 years ago

Thank you for the bug report but this is the wrong repo. Please reopen you issue at https://github.com/fuel/orm