I’m not sure if I’m missing something obvious here but can models perform finds on other models?
For example model A has a createAndSave method and wants to check that a referenced object doesn’t already exist in Couchbase before creating new one. I require the other model which is a child of Model A then call its find method. The callback method of that find doesn’t seem to get triggered.
Is this a bug. Please let me know if you need any code examples.
I have two files both representing a model each. One has reference to the other. lets say
parent.js
// assumes that couchbase and ottoman are setup and ready for action
const parent = ottoman.model("Parent", {
child: [{ref: "Child"}],
baz: "string"
})
parent.someFunction = function(param, callback) {
child.find({foo: param}, function(err,result) {
if (err) {
console.log(err)
callback(err, null)
} else if (result && result.length > 0) {
console.log('found')
callback(null, 'found')
} else {
console.log('not found')
callback(null, 'not found')
}
})
}
module.exports = parent
child.js
// assumes that couchbase and ottoman are setup and ready for action
const child= ottoman.model("Child", {
foo: "string",
bar: "string"
})
module.exports = child
The console.logs from someFunction never get called. If I take the child.find out of the someFunction and place that in the controller then all works as expected. Which is why I think there is a problem calling methods between models.