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

Nested Select Using the Wrong ID #420

Open
eni9889 opened this issue Aug 10, 2022 · 1 comment
Open

Nested Select Using the Wrong ID #420

eni9889 opened this issue Aug 10, 2022 · 1 comment

Comments

@eni9889
Copy link

eni9889 commented Aug 10, 2022

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
Copy link
Author

eni9889 commented Aug 10, 2022

This was my solution for now a160cb0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant