administrate
administrate copied to clipboard
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 :
and on program#edit :
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?
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.
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.
@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.