-
Notifications
You must be signed in to change notification settings - Fork 148
Description
I'm trying to allow a serializer to define a has_many on some association only if it's actually be included from the serializer options. Seems like a pretty obvious use case ?
Would you be open to a PR that gives access to @includes to the :if proc on associations?.
I also noticed there's now an included boolean that's passed in to Relationship, could we pass that to the conditional proc?
ie:
SomeSerializer.new(collection, include: [:some_association])
class SomeSerializer
has_one :some_association, if: -> (record, params, included) { included }
I'm having a hard time understanding the lazy_load_data option in relationships as I'm not entirely sure what it's supposed to do or what the "lazy" is referring to, but ActiveRecord always lazy loads its own associations unless eager loaded so I'm confused by the docs that suggest using lazy_load_data: true won't serialize relationships if they're not eager loaded.