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

Allow scope to accept field as argument for Field::BelongsTo #2652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Nitr
Copy link

@Nitr Nitr commented Aug 27, 2024

#2459

Sometimes need to do a query dependent on resource's state, field and etc in forms.

I used to use combination of Field::Select for form page and Field::BelongsTo for collection page like this:

ATTRIBUTE_TYPES = {
  customer_id: Field::Select.with_option(collection: ->(field) { Customer.some_scope.where(column: field.resource.column) }), 
  customer: Field::BelongsTo
}
COLLECTION_ATTRIBUTES = [:customer]
FORM_ATTRIBUTES = [:customer_id]

But I've noticed that many people are confused by this and that it's more common to have only one field customer like this:

ATTRIBUTE_TYPES = { 
  customer: Field::BelongsTo.with_option(scope: ->(field) { Customer.some_scope.where(column: field.resource.column) }), 
}
COLLECTION_ATTRIBUTES = [:customer]
FORM_ATTRIBUTES = [:customer]

I've just found this gem but it doesn't check arity.

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

Successfully merging this pull request may close these issues.

1 participant