Some users would like to get all or some fields automatically from it's model class.
We can check the model attributes and foreign keys similar to how we discover them in the resource generator.
Current workarounds
Declare them manually as fields or build your own method.
Possible API
[!NOTE]
Naming is TBD
# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# name :string
# age :string
# is_admin :integer
# created_at :datetime not null
# updated_at :datetime not null
class User < ApplicationRecord
end
# before
class Avo::Resources::User < Avo::BaseResource
def fields
field :id, as: :id
field :name, as: :text
field :age, as: :number
field :is_admin, as: :boolean
field :created_at, as: :date_time
field :comments, as: :has_many
end
end
# after
class Avo::Resources::User < Avo::BaseResource
def fields
# adds fields for all attributes
discover_fields
# selectively pick fields
discover_fields only_attributes: [:id, :name]
discover_fields except_attributes: [:age]
# associations
discover_associations
end
end
Feature
Some users would like to get all or some fields automatically from it's model class. We can check the model attributes and foreign keys similar to how we discover them in the resource generator.
Current workarounds
Declare them manually as
field
s or build your own method.Possible API