Closed ambrumyan closed 9 years ago
you want to use a static function, if you need to access a function without an id. but the method you have uses this._id so you will need to pass in an id.
DepartmentSchema.statics.superDo = function DepartmentSchema$hello(query$id){
return Department.find({
_id:query$id
});
}
The behaviour is expected though the message is less than obvious
Well It doesn't solves my problem, I am trying to create custom routes for post requests, if I will use statics I will need to add "finder" to the URL , is there any other way to do that without statics?
Well you don't need 'finder' anymore with statics. I should update the docs. The gists of the problem is if your query requires an id, you will have to pass the id, somehow. You can stick it in the query in the parameters in the session. Lots of options. The error message you are receiving is because the id isn't there.
On Sun, Mar 22, 2015 at 11:46 PM ambrumyan notifications@github.com wrote:
Well It doesn't solves my problem, I am trying to create custom routes for post requests, if I will use statics I will need to add "finder" to the URL , is there any other way to do that without statics?
— Reply to this email directly or view it on GitHub https://github.com/jspears/mers/issues/45#issuecomment-84843101.
When I am trying to add new method to Schema
DepartmentSchema.methods.superDo = function DepartmentSchema$hello(data){ return Department.find({ _id:this._id }); }
getting such error
{"status":1,"error":"Cast to ObjectId failed for value \"superDo\" at path \"_id\""}
URL is -> /department//superDo
When I am trying to do for instance like this
/department/550ad5972aa071895a364180/superDo
Works perfect