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

Named modifiers don't work with optional arguments #1293

Closed
onufriievkyrylo opened this issue Apr 12, 2019 · 5 comments
Closed

Named modifiers don't work with optional arguments #1293

onufriievkyrylo opened this issue Apr 12, 2019 · 5 comments
Labels

Comments

@onufriievkyrylo
Copy link

I want to provide some additional argument in named modifier, but when I'm calling it this way

query.midify('filters', [filter_query])

it's try to find named modifier with [filter_query].
Is it expected behavior?

@koskimas
Copy link
Collaborator

Cannot reproduce based on your example. Works on my tests.

@onufriievkyrylo
Copy link
Author

onufriievkyrylo commented Apr 12, 2019

@koskimas Maybe my example wasn't so clear.
My model file:

class Person extends Model {
  staic modifiers = {
    filters: (query, context) => query.where({ age: context.age })
  }
}

calling this modifier

Person.query()
  .modify('filters', { age: 21 })

I'm expecting to have { age: 21 } in my modifier second argument (context). But instead I doesn't have second argument at all (undefined);

@koskimas
Copy link
Collaborator

Oh, ok. Yeah, that's a known limitation with the modifiers. Fixing this is a breaking change and needs to wait for 2.0

@koskimas koskimas reopened this Apr 13, 2019
@koskimas
Copy link
Collaborator

koskimas commented Apr 15, 2019

As a workaround, you can use the query context

class Person extends Model {
  static modifiers = {
    filters: query => query.where({ age: query.context().age })
  }
}

Person.query()
  .mergeContext({ age: 21 })
  .modify('filters')

@koskimas
Copy link
Collaborator

Fixed in v2.0 branch.

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

No branches or pull requests

2 participants