Closed simonworkhouse closed 2 years ago
Feedback on this would be appreciated.
Fixes #127
Thank you for the valuable contribution. I did a complete rewrite for the whole package and changed how this feature works. In the new refactor, it actually uses normal relationships, and should be easy and straightforward like default Laravel relationships. Although, that refactor is incomplete.
I'm still not happy with the overall performance (I believe we can reduce number of executed queries), if you want to check it out, see https://github.com/rinvex/laravel-attributes/tree/refactor-to-native-laravel-relationships
Currently no plans to merge that rewrite, but hopefully sometime I can get it to a stable state, improve performance and release it. Any help with that branch would be much appreciated! 🙂
This addresses the issue raised here https://github.com/rinvex/laravel-attributes/issues/127, restructures the tests slightly and adds some stress tests, attribute value tests and tests to make sure that the attributable cache is cleared correctly.
Essentially, since the entity attributes are stored in the static property
static::$entityAttributes
and since thegetEntityAttributes()
function doesn't re-fetch the attributes if they have already been set for the current entity, any additional attributes that are created in the current request weren't available to the entity.I have also included a fix to the Attribute model
setEntitiesAttribute
method so that it doesn't keep adding an event handler for thesaved
event every time that the method is called.