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 passing an Object to virtual setter #10

Closed
antoinemaillard opened this issue Jul 31, 2017 · 1 comment
Closed

allow passing an Object to virtual setter #10

antoinemaillard opened this issue Jul 31, 2017 · 1 comment

Comments

@antoinemaillard
Copy link

Hi Alex,
Thanks for this simple yet very useful plugin!

I have a question, though: why don't you allow your virtual setter to receive the very same object that you can pass to -.all setter?

It would be very convenient to be able to pass back the same structure of document that is retrieved (without patching internationalized fields to add the .all prefix).

Here is what I would suggest for the virtual setter:

    schema.virtual(path)
            .get(function (param) {
                // embedded and sub-documents will use language methods from the top level document
              var owner = this.ownerDocument ? this.ownerDocument() : this
              return param && param[owner.getLanguage()]
            })
            .set(function (value) {
                // embedded and sub-documents will use language methods from the top level document
              var owner = this.ownerDocument ? this.ownerDocument() : this
              if (typeof (value) === 'string') {
                // if the value is a string, we assume this is the value for default language
                this.set(path + '.' + owner.getLanguage(), value)
              } else {
                // if the value is not a string, it may be an object containing all languages variations. Let's pass it to the .all setter
                this.set(path + '.all', value)
              }
            })

What do you think about that?

@alexsk
Copy link
Owner

alexsk commented Aug 12, 2017

Thank you for the proposal.
Implemented under v3.0.0, as .all getter/setter was removed (see #11 for details).

@alexsk alexsk closed this as completed Aug 12, 2017
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

2 participants