You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# The base serializer, e.g. chapters of a bookclassChapterBlueprint < Blueprinter::Baseidentifier:idview:normaldofields:name,:descriptionendview:extendeddoinclude_view:normalassociation:sections,blueprint: SectionBlueprint# Here I have to write view: :normal, otherwise it only renders the section's :idendend# Each chapter has 0 to n sectionsclassSectionBlueprint < Blueprinter::Baseidentifier:idview:normaldofields:name,:page_refendview:extendeddoinclude_view:normalfields:created_at,:updated_atendend
Hi @araccaine, whatever you define at the root level, automatically already becomes your default view. So you could still achieve this with -
# The base serializer, e.g. chapters of a book
class ChapterBlueprint < Blueprinter::Base
identifier :id
fields :name, :description
view :extended do
association :sections, blueprint: SectionBlueprint # Here it renders the section's default view
end
end
# Each chapter has 0 to n sections
class SectionBlueprint < Blueprinter::Base
identifier :id
fields :name, :page_ref
view :extended do
fields :created_at, :updated_at
end
end
Now after reading my own code and this issue again after a few weeks I see that my question was not what I intended to achieve. What I really need is:
The :extended view would be the default view
The :normal view (with less information/fields) would be used only for special occasions.
A better naming may be something like :detailed and :simple, where :detailed is the default view with more fields. For the other way round (like my first question was worded) your suggestion would work. But having more fields in the "default view" would not work.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Is there an existing issue for this?
Describe your question or ask for support
Question
Is there something like a "default view" that I can set when using an
association
?Currently, I also have to specify an association with an explicit view:
Example
What I am looking for
Something like this:
The text was updated successfully, but these errors were encountered: