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

Virtual set function not called when value is object #1154

Closed
evanrs opened this issue Oct 12, 2012 · 4 comments
Closed

Virtual set function not called when value is object #1154

evanrs opened this issue Oct 12, 2012 · 4 comments

Comments

@evanrs
Copy link

evanrs commented Oct 12, 2012

I have a mongoose schema with a virtual of mixed type. For example:

    var mongoose = require('mongoose') // version 3.3.1

    var FooSchema = new mongoose.Schema( { x: Number } );

    FooSchema.virtual('v').set( function(value){ 
      console.log("SETTING", value); 
    });

    var Foo = mongoose.model('Foo', FooSchema);

    new Foo( { v:1 } );
    new Foo( { v:[] } );
    new Foo( { v:{} } );

When I run this code I get:

SETTING 1
SETTING []

As you'll notice it never shows "SETTING {}", any reason why this doesn't work?

Reference to question on Stack Overflow

@aheckmann
Copy link
Collaborator

Looks like a bug. Will look into it.

Which version of mongoose?

On Oct 12, 2012, at 2:12 PM, evanrs notifications@github.com wrote:

I have a mongoose schema with a virtual of mixed type. For example:

var mongoose = require('mongoose')

var FooSchema = new mongoose.Schema( { x: Number } );

FooSchema.virtual('v').set( function(value){ 
  console.log("SETTING", value); 
});

var Foo = mongoose.model('Foo', FooSchema);

new Foo( { v:1 } );
new Foo( { v:[] } );
new Foo( { v:{} } );

When I run this code I get:

SETTING 1
SETTING []
As you'll notice it never shows "SETTING {}", any reason why this doesn't work?

Reference to question on Stack Overflow


Reply to this email directly or view it on GitHub.

@evanrs
Copy link
Author

evanrs commented Oct 13, 2012

Ah, missed that, it's version 3.3.1

@evanrs
Copy link
Author

evanrs commented Nov 28, 2012

Thanks Aaron, I really appreciate your work on Mongoose.

@aheckmann
Copy link
Collaborator

:D

On Wed, Nov 28, 2012 at 11:03 AM, evanrs notifications@github.com wrote:

Thanks Aaron, I really appreciate your work on Mongoose.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1154#issuecomment-10816080.

Aaron
@aaronheckmann https://twitter.com/#!/aaronheckmann

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