invoice_serializer.rbСериализация УСЛОВНО на активной модели сериализаторы
class InvoiceSerializer < ActiveModel::Serializer
attributes :id, :document_no, :customer_id, :currency_id, :date,
:due_date, :notes, :invoice_status_id, :total, :tax_total, :grand_total
# This is not working, associated objects are still rendered
unless @object.respond_to? :count
has_many :invoice_lines
end
has_many :invoice_payments
has_one :customer
has_one :invoice_status
end
Это мой класс сериализатору. У меня есть две ассоциации has_many, и я не хочу их в коллекции. Я только хочу, чтобы они были в единственном числе. Чтобы быть более ясным, мне не нужна ассоциация has_many в индексе индексов #, это плохо влияет на производительность, но я хочу, чтобы они отображались в счетах # show, invoices # edit actions.
Как это достичь? Как я могу связать модели условно?