Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Issues
  • #1877
Closed
Open
Issue created Jan 29, 2021 by YUNOO LTD@DavidGeismarLtd

Pass option to Field::HasOne to only display specific columns

  • What would you like to be able to do? Can you provide some examples?

Let's say I have a Program has_one Product as: :item where Product handles polymorphic association with item_type and item_id column.

In my Program dashboard, I want to make product editable :

 ATTRIBUTE_TYPES = {
  product: Field::HasOne,
  }
SHOW_PAGE_ATTRIBUTES = %i[
  product
]

FORM_ATTRIBUTES = %i[
 product
]

In the administrate UI you end up with on program#show :

Screenshot 2021-01-29 at 08 33 04

and on program#edit :

Screenshot 2021-01-29 at 08 34 23

On both page the item field from Product is visible or editable, but in that case it doesn't make sense to show or edit the item column because I am already on the page of the resource I want to edit.

  • How could we go about implementing that?

Is there an option I can pass to Field::HasOne to tell it to display only certain fields ? Something like : product: Field::HasOne.with_options(except: %i[ item_type item_id])

  • Can you think of other approaches to the problem?
Assignee
Assign to
Time tracking