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

Add automatic field detection in resources #3390

Open
adrianthedev opened this issue Nov 6, 2024 · 5 comments
Open

Add automatic field detection in resources #3390

adrianthedev opened this issue Nov 6, 2024 · 5 comments
Assignees

Comments

@adrianthedev
Copy link
Collaborator

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 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
Copy link
Contributor

This issue has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Nov 22, 2024
@Paul-Bob Paul-Bob removed the Stale label Nov 22, 2024
@ObiWanKeoni
Copy link
Contributor

@Paul-Bob @adrianthedev Do you mind if I take a crack at this one?

@Paul-Bob
Copy link
Contributor

Sure @ObiWanKeoni, thank you!

We don't have a lot of research on this but basically we would like to browse and manipulate the database (and all the attribute accessors of an model) without need to configure each field individually.

Let me know if you need any help with this

@ObiWanKeoni
Copy link
Contributor

Hey @Paul-Bob 👋

FYI - I do have a working prototype locally but before I commit a substantial feature change, I'm working to get the necessary internal approvals from my workplace.

@Paul-Bob
Copy link
Contributor

FYI - I do have a working prototype locally but before I commit a substantial feature change, I'm working to get the necessary internal approvals from my workplace.

Amazing! We would love to see it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants