Skip to content

Conditional lazy_load_data for relationships #123

@vbeliaiev

Description

@vbeliaiev

Expected Behaviour

I need to include/exclude data for relationships depending on external parameter given to serializer.

For example BundleSerializer.new(bundle, params: { lazy_load_instruments_data: true }) should exclude the data for relationships.

And BundleSerializer.new(bundle, params: { lazy_load_instruments_data: false }) should include the data

It could be resolved by passing the proc as an argument to lazy_load_data

    has_many :instruments, lazy_load_data: Proc.new { |_, params| params[:lazy_load_instruments_data] == true }, links: {
        related: -> (object) {
          url_helpers.instruments_url(related_id: object.id)
        }
    }

Actual Behaviour

Even if we pass a proc as in example above it always count the lazy_load_data as true because:

output_hash[key][:data] = ids_hash_from_record_and_relationship(record, serialization_params) || empty_case unless lazy_load_data && !included

https://github.com/jsonapi-serializer/jsonapi-serializer/blob/master/lib/fast_jsonapi/relationship.rb#L48

Steps to Reproduce the Problem

  1. Pass conditional Proc as value of lazy_load_data
  2. It always count lazy_load_data: true even if Proc returns false

Specifications

  • Version: 2.1.0
  • Ruby version: 2.7.1p83

It's not a bug but the feature request, I can add it just want to check if we are ok with this behaviour

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions