avo icon indicating copy to clipboard operation
avo copied to clipboard

Fields for additional column values/associations while attaching a record to another

Open carbonatedcoder opened this issue 1 year ago • 6 comments

Feature

Apologies if this does exist or there is a suggested way to handle this, but we could not find a mention of it in the 3.0 docs.

The ability to specify additional column values or associations while attaching a record, via a join record, to another.

Example scenario:

Assume you have a team record that has many users via a join record called team_users. In addition to a team_id and user_id column on the join record, assume there is a third non-nullable column/association on it called role_id.

When trying to an attach a user to a team via team's show page, an attachment will fail because a team_user record needs that role association value set at the time of creation. In reference to the popup overlay that shows when clicking "Attach user", is there any way to specify additional column values or associations to be set on the join record at that time?

Current workarounds

  • Only current workaround would be to set a column default value and adjust it after attachment/creation.

carbonatedcoder avatar Feb 12 '24 19:02 carbonatedcoder

Hello @carbonatedcoder

Currently Avo don't support and don't have any recipe on how to handle this scenarios.

There are some plans to improve the attach experience:

  • https://github.com/avo-hq/avo/issues/2115
  • https://github.com/avo-hq/avo/issues/2116
  • https://github.com/avo-hq/avo/issues/1937
  • https://github.com/avo-hq/avo/issues/2115

In my opinion the current workaround that you suggested is not ideal but is the best way to handle this for now.

Paul-Bob avatar Feb 13 '24 13:02 Paul-Bob

@Paul-Bob, thank you for your reply and suggestions! We'll work around it for now and look forward to perhaps Avo eventually expanding this functionality.

carbonatedcoder avatar Feb 13 '24 15:02 carbonatedcoder

Anytime! If you find a way to implement it any PR / recipe is welcomed.

Paul-Bob avatar Feb 13 '24 15:02 Paul-Bob

Another idea that comes to mind is to create an action that takes that custom field and hidden one (the record on which it's attached. Then hide the attach button and add the attach action instead.

adrianthedev avatar Feb 13 '24 19:02 adrianthedev

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

github-actions[bot] avatar Feb 29 '24 01:02 github-actions[bot]

Another idea that comes to mind is to create an action that takes that custom field and hidden one (the record on which it's attached.

Then hide the attach button and add the attach action instead.

Hi @adrianthedev Please could you expand on how this could work? I'd be very interested in trying this approach in the meantime.

rctneil avatar May 17 '24 16:05 rctneil

Approach

Possible API:

field :users, as: :has_and_belongs_to_many, extra_fields: do
  field :status, as: :text
  field :date, as: :date
end

Helpful PR where we add extra_fields: https://github.com/avo-hq/avo/pull/2650

### Nice to have's
- [ ] validations

adrianthedev avatar Jul 11 '24 06:07 adrianthedev