I'm using the fast_jsonapi gem to serve a react front-end. I have 2 models :
class Store < ApplicationRecord
has_many :opening_hours
end
and
class OpeningHour < ApplicationRecord
belongs_to :store
end
I'm StoreController#new, i just want to build a new Store + 7 "opening_hours" children, and send the corresponding JSON :
def new
store = Brand.find(params[:brand_id]).stores.new()
[1,2,3,4,5,6,7].map{ |i| store.opening_hours.new(weekday: i) }
render json: StoreSerializer.new(store, options).serializable_hash
end
private
def options
@options ||= {include: %i[opening_hours]}
end
Here is my serializer :
class StoreSerializer
include FastJsonapi::ObjectSerializer
attributes :name, :brand_id, :formatted_address, :address_street_number, :address_line1, :address_line2, :address_zip, :address_city, :address_country, :phone, :internal_code
has_many :opening_hours
end
Problem is : in the generated JSON, i only get the first "opening_hours" element :

Whereas i surely have the 7 children in the relationships > opening_hours > data.