rinvex / laravel-attributes

⚠️ [ABANDONED] Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
MIT License
433 stars 104 forks source link

Clearing the Attributable static "cache" when creating attributes #132

Closed simonworkhouse closed 2 years ago

simonworkhouse commented 3 years ago

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 the getEntityAttributes() 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 the saved event every time that the method is called.

simonworkhouse commented 3 years ago

Feedback on this would be appreciated.

simonworkhouse commented 3 years ago

Fixes #127

Omranic commented 2 years ago

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! 🙂