nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
310 stars 57 forks source link

calculateCacheKey may produce same key for different parameters #246

Closed matej21 closed 4 years ago

matej21 commented 7 years ago

Hi, I use marc-mabe/php-enum for enums in php and when I pass it to a findBy method, nextras/orm may reuse entity iterator from a cache. It happens because orm uses json_encode to calculate a cache key and Enum does not implement JsonSerializable, so PHP exports all public properties - which is none.

Not sure how to solve it, maybe enforce to implement JsonSerializable on object parameters? or use spl_object_hash instead?

hrach commented 7 years ago

spl_object_hash could return same hashes for different objects, so I suspect that the problem could persist. What about using php's native serialize?

hrach commented 4 years ago

I have written a test and the problem is not there (for now). The enums are already "prepared" for SQL -> e.g. their name is used in this phase now. (When using them correctly with property wrapper). This may have been different back in 2017, but closing as resolved now.