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

Pass parent to mutator / default value function #795

Open
m-mohr opened this issue Dec 15, 2022 · 0 comments
Open

Pass parent to mutator / default value function #795

m-mohr opened this issue Dec 15, 2022 · 0 comments

Comments

@m-mohr
Copy link

m-mohr commented Dec 15, 2022

Is your feature request related to a problem? Please describe...

I have some fields where the default value or mutator depends on another value of the data passed in.

Describe the solution you'd like

I'd like to have that the parent record is passed into the functions

Describe alternatives you've considered

I'm not aware of any alternatives except for doing everything manually before creating/inserting the data.

Additional context

As an example, the make function could easily be adapted as such I think:

  make(value: any, _parent: Record, key: string): any {
    value = value !== undefined ? value : this.value

    // Default Value might be a function (taking no parameter).
    let localValue = value

    if (typeof value === 'function') {
      localValue = value(_parent) // Pass in _parent here
    }

    return this.mutate(localValue, key, _parent) // Pass in _parent here
  }
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