Skip to content

Allow conditional relationships to see what's been included #21

@bradrobertson

Description

@bradrobertson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions