analogueorm / analogue

Analogue ORM : Data Mapper ORM for Laravel/PHP
MIT License
632 stars 51 forks source link

Unable to save foreign keys in 5.5 #214

Closed tabennett closed 6 years ago

tabennett commented 6 years ago

Since upgrading to 5.5, this line in analogue/src/System/Aggregate.php is now breaking our tests:

return $foreignKeys + $attributes;

The order needs to be switched there, otherwise there's no way to set foreign keys on the entity because they'll always be overridden with null values:

return $attributes + $foreignKeys;
RemiCollin commented 6 years ago

Thanks for reporting this. Unfortunately just switching the order is not enough, as it will cause foreign keys which are calculated from the relationship itself to be overridden by previous values.

We need to support both way, by comparing the relationship & the foreignKey attribute to the entity's original state in cache. We can probably assume the user intente if one or the other is changed, and drop an exception if both have been updated.

Do you think you can provide more details about the context (which relationship is used, some userland code) ?

RemiCollin commented 6 years ago

Pushed a fix : https://github.com/analogueorm/analogue/pull/215

Can you confirm me it works on your project ?

tabennett commented 6 years ago

Just pulled it down and all tests are green now! 👍 Thanks Remi!