Netflix / fast_jsonapi

No Longer Maintained - A lightning fast JSON:API serializer for Ruby Objects.
Apache License 2.0
5.07k stars 425 forks source link

Relationship scope #448

Open kapso opened 4 years ago

kapso commented 4 years ago

Is there a way to add scope to relationship, so something like this

Serializer:

class CompanySerializer
  include FastJsonapi::ObjectSerializer

  has_many :employees_temp, scope: ->(record) { record.employees.temp }, serializer: EmployeeSerializer
  has_many :employees_full_time, scope: ->(record) { record.employees.full_time }, serializer: EmployeeSerializer
end

Given the following models:

class Company < ApplicationRecord
  has_many :employees
end

class Employee < ApplicationRecord
  scope :temp, -> { where(type: 'temp') }
  scope :full_time, -> { where(type: 'full_time') }
end
kapilnarula commented 4 years ago

It seems Netflix has abandoned this project. The community created a new fork to continue supporting this project. Please refer

https://github.com/fast-jsonapi/fast_jsonapi

On Wed, 6 Nov, 2019, 12:42 PM Kapil, notifications@github.com wrote:

Is there a way to add scope to relationship, so something like this

Serializer:

class CompanySerializer include FastJsonapi::ObjectSerializer

has_many :employees_temp, scope: ->(record) { record.employees.temp }, serializer: EmployeeSerializer has_many :employees_full_time, scope: ->(record) { record.employees.full_time }, serializer: EmployeeSerializerend

Given the following models:

class Company < ApplicationRecord has_many :employeesend class Employee < ApplicationRecord scope :temp, -> { where(type: 'temp') } scope :full_time, -> { where(type: 'full_time') }end

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Netflix/fast_jsonapi/issues/448?email_source=notifications&email_token=ACEAHZM3ZUIG7LPQ7CTGZUTQSJU4HA5CNFSM4JJQVLXKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HXEMOGQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEAHZJAKXZUDZGZLY7VMLTQSJU4HANCNFSM4JJQVLXA .