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

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

Open
DavidGeismarLtd opened this issue Jan 29, 2021 · 3 comments
Open

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

DavidGeismarLtd opened this issue Jan 29, 2021 · 3 comments
Labels
namespacing models with a namespace nested-resources

Comments

@DavidGeismarLtd
Copy link

  • 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?
@pablobm
Copy link
Collaborator

pablobm commented Feb 4, 2021

Unfortunately, this is not possible at present.

For this to work, the HasMany field would have to link to a different version of the Product dashboard. One under /admin/programs/:id/products, as opposed /admin/products. This way, it would be able to use the URL to identify that a different dashboard (or dashboard configuration) should be used.

This falls under the category of changes to namespacing and dashboard definition that should be handled at some point. For now, I can only thank all of you coming to us with use cases, as these will help us create a better solution in the future.

@richardonrails
Copy link

richardonrails commented May 13, 2022

I'd like to be able to include a HasOne field on on a Show page but not have the entire object (and all of its own nested HasOne entire objects) displayed.

In some cases I'd rather just have a simple link to the referenced object. Is there anyway to do that right now? I was picturing something like Field::HasOne.with_options(expand: false)

I suppose this is also related to #1559.

@pablobm
Copy link
Collaborator

pablobm commented Jun 23, 2022

@richardonrails - I recommend creating a new field type; say Field::HasOneLink that behaves as you expect. You can copy (or perhaps inherit) the existing Field::HasOne and build on top of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
namespacing models with a namespace nested-resources
Projects
None yet
Development

No branches or pull requests

3 participants