Skip to content

Field::HasManyとField::NestedHasManyをcollection_attributesに移行する #16

@goosys

Description

@goosys

Issues

Tasks

Usage

class Book < ApplicationRecord
  has_many :book_printing_histories
  accepts_nested_attributes_for :book_printing_histories, allow_destroy: true

  def least_book_printing_histories
    book_printing_histories.where(id: book_printing_histories.order(printing_number: :desc).limit(1).pluck(:id))
  end
end
class BookDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    book_printing_histories: Field::NestedHasMany.with_options(
      parent: :book,
      skip: [:book]
    ),
    least_book_printing_histories: Field::NestedHasMany.with_options(
      dashboard_name: "BookPrintingHistoryDashboard",
      skip: [:book],
      collection_attributes: %i[printing_number printed_at]
    ),

image

Todos

  • spec

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions