Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify Record Type and Serializer Class for all relations #17

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/serializers/alchemy/json_api/element_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class ElementSerializer
)
belongs_to :parent_element, record_type: :element, serializer: self

belongs_to :page
belongs_to :page, record_type: :page, serializer: PageSerializer

has_many :essences, polymorphic: true do |element|
element.contents.map(&:essence)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EssenceNodeSerializer
essence&.node&.name
end

belongs_to :node
belongs_to :node, record_type: :node, serializer: NodeSerializer

with_options if: proc { |essence| essence.node.present? } do
attribute :name do |essence|
Expand Down
4 changes: 2 additions & 2 deletions app/serializers/alchemy/json_api/page_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class PageSerializer
:updated_at,
)

belongs_to :language
belongs_to :language, record_type: :language, serializer: LanguageSerializer

has_many :elements
has_many :elements, record_type: :element, serializer: ElementSerializer
has_many :fixed_elements, record_type: :element, serializer: ElementSerializer

has_many :all_elements, record_type: :element, serializer: ElementSerializer do |page|
Expand Down