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

Scope select options to a particular resource? #2459

Open
wengzilla opened this issue Nov 17, 2023 · 0 comments
Open

Scope select options to a particular resource? #2459

wengzilla opened this issue Nov 17, 2023 · 0 comments

Comments

@wengzilla
Copy link

I would like to scope a BelongsTo field to a particular set of things based on the resource, but I'm not sure how to achieve this...

Right now, I have the following relationship: Companies have many Departments which have many Employees. Or, in other words, Employee belongs to a Department which belongs to a Company.

I want to have a field on my EmployeeDashboard that looks as follows:

ATTRIBUTE_TYPES = {
    departments:
      Field::BelongsTo.with_options(scope: ->(resource) { resource.company.departments }),
  }.freeze

I could monkey patch the scope call to pass in resource, but is there a more elegant way to do this?

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

No branches or pull requests

1 participant