grape-entity icon indicating copy to clipboard operation
grape-entity copied to clipboard

Wrong except option for nested entities

Open yoursdearboy opened this issue 10 years ago • 1 comments

Good day. I have a problem with except option. If I use it on entity Patient like this

Patient::Entity.represent(patient, except: [testssets: [:patient]]).as_json

all works great, but I have an infinite recursion if use it on opposite entity Testsset

Testsset::Entity.represent(testsset, except: [patient: [:testssets]]).as_json

I think that there's a problem with Exposure::Base#serializeable_value. All works fine in first case because it is one-to-many relation and handled by this code

partial_output.map(&:serializable_hash)

In second case it is handled by this code (with options argument)

partial_output.serializable_hash(options)

And lately options generated for a nested entity are rewritten in Options#merge method like this

options = {except: [:testssets]}
new_options = {except: [{patient: [:testssets]}]}
options.merge(new_options)

So, now we have except fields for a nested entity such as for the parent. It seems that this code is broken and options hash should be passed in both cases. And except fields shouldn't be merged.

yoursdearboy avatar Dec 13 '15 12:12 yoursdearboy

Indeed, it just wasn't implemented for nested except's, please contribute.

dblock avatar Dec 14 '15 12:12 dblock