0

I have a model Organisation. This model has_many organisation_branches. The organisation_branch has the address details in which the city_id is present, which refers to the city table.

organisation.rb:

class Organisation < ApplicationRecord
  has_many :organisation_branches
end

organisation_branch.rb

class OrganisationBranch < ApplicationRecord
  belongs_to :organisation
  belongs_to :city
end

organisation_serializer:

class OrganisationSerializer
  include FastJsonapi::ObjectSerializer
  attributes :id,:org_id,:organisation_name

  has_many :organisation_branches
end

I need to display the Branch details with the name of the city retrieved from the city table. All this needs to be shown when an organisation is viewed.

Nandhini
  • 645
  • 7
  • 21
  • Just to clarify your question a bit, you're interested in displaying a nested attribute, `organisation_branch` inside the Serializer, right? This is a question about getting those details in the serializer? – Veridian Dynamics Apr 13 '19 at 18:05
  • @VeridianDynamics yes I need the organisation branch details along with the city name not jus the city id – Nandhini Apr 14 '19 at 07:38
  • What have you attempted to solve the problem? – max Apr 14 '19 at 10:42
  • @max I am planning to have a separate serializer for organisation_branch, from which I will get the city_id and retrieve from the City table. I wanted to know the best optimal solution to do this – Nandhini Apr 15 '19 at 09:12

0 Answers0