platanus / activeadmin_addons

Extends ActiveAdmin to enable a set of great optional UX improving add-ons
MIT License
763 stars 288 forks source link

Nested Select Using the Wrong ID #420

Open eni9889 opened 2 years ago

eni9889 commented 2 years ago

I have the following scenario for a trucking company. The company runs loads and those loads are run by a driver who works for a carrier. There are multiple carriers and they share drivers.

      f.input :driver_id,
              as:                   :nested_select,
              minimum_input_length: 0,
              level_1:              {
                attribute: :carrier_id
              },
              level_2:              {
                attribute: :driver_id,
                url:       search_drivers_path
              }

And the following models:

Driver:
  belongs_to :carrier 

Carrier:
  has_many :drivers
  belongs_to :group
  has_many :group_drivers, through: :group, class_name: 'Driver', source: :drivers

Group:
  has_many :carriers
  has_many :drivers, through: :carriers

Load
  belongs_to: :carrier 
  belongs_to :driver
search_drivers_path - Returns all of the drivers that can work with a carrier, based on the group. 

Everything works fine in the drop down when creating a load, but when someone goes to edit the record after it has been saved the form uses the carrier_id from the driver instead of the load.

Can anyone advise?

eni9889 commented 2 years ago

This was my solution for now https://github.com/platanus/activeadmin_addons/commit/a160cb00ebb7034a4d827752fc7850c1543b4973