mongoose-currency
mongoose-currency copied to clipboard
Failure when inside nested schema
I have the following example, which works as expected:
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
// Will add the Currency type to the Mongoose Schema types
require('mongoose-currency').loadType(mongoose);
var Currency = mongoose.Types.Currency;
/**
* Our Schema
*/
var ProgramSchema = new Schema({
"created": {
type: Date,
"default": Date.now
},
name: {
type: String,
"default": ''
},
value: Currency,
displayName: String,
rateSheet: {
termPeriod: {
type: String,
"default": ''
},
buyoutOptions: [{
name: {
type: String,
"default": ''
},
terms: [],
costs: [{
min: {
type: Currency
},
max: {
type: Currency,
"default": 0
},
rates: []
}]
}]
}
});
However, this version of the same schema doesn't work:
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
env = process.env.NODE_ENV || 'development',
config = require('../../config/config')[env],
Schema = mongoose.Schema;
// Will add the Currency type to the Mongoose Schema types
//require('mongoose-currency').loadType(mongoose);
require('mongoose-currency').loadType(mongoose);
var Currency = mongoose.Types.Currency;
// Buyout Options Schema
var buyoutOptionsSchema = new Schema({
name: {
type: String,
"default": ''
},
terms: [],
costs: [costsSchema]
});
// Costs Schema
var costsSchema = new Schema({
min: {
type: Currency
},
max: {
type: Currency,
"default": 0
},
rates: []
});
/**
* Program Schema
*/
var ProgramSchema = new Schema({
"created": {
type: Date,
"default": Date.now
},
name: {
type: String,
"default": ''
},
displayName: String,
rateSheet: {
termPeriod: {
type: String,
"default": ''
},
buyoutOptions: [buyoutOptionsSchema]
}
});
In the second example, min and max do not save as Currency.
Thanks for submitting this. I'm pretty busy lately, but wanted to let you know that I did see it and will fix it.
If you could write a failing test, that would be extremely helpful. That way I just have to fix the bug. Let me know if you'd be able to do that.
Thanks!
I'll see if I can get to this. Thanks!
Sounds great! Thanks for reporting it. Other than this case where it didn't work, did you find the library useful?
El Oct 9, 2013, a las 8:43 PM, Matt Miller [email protected] escribió:
I'll see if I can get to this. Thanks!
— Reply to this email directly or view it on GitHub.