Closed daton89 closed 6 years ago
Because of your defaults, all your models will be given a reference to the same collection (see code below)
defaults: {
name: '',
files: new Files()
}
This is because new Files()
is instantiated once and not each time you create a model instance. Try changing your defaults to be a function instead. This function will be evaluated each time a new model is instantiated thus giving you a reference to a new collection instead of the same one.
defaults() {
return {
name: '',
files: new Files()
};
},
There is another potential issue (same concept) with your defaults for the File
model:
defaults: {
_id: undefined,
originalname: '',
createdOn: Date.now()
}
The line Date.now()
will be evaluated when the model is extended and not when the model is created. So all your models will be given the same exact date, which I am assuming is not your intention. I would suggest assigning defaults as a function returning an object to avoid that potential issue.
defaults() {
return {
_id: undefined,
originalname: '',
createdOn: Date.now()
};
}
I fall in a strange error initializing the related Model or Collection in the default of the related model:
These are my Models / Collections
when i use a ChemicalAgent, i populate it with name and files, then when i try to instantiate a new Model the files i populate before is present in new model even if i create a new instance of model. an example:
so if i don't initialize
new Files()
in model declaration this issue doesn't happen