Report about Hook event is not available
Hi,
I have a problem when making request from client (PUT method). I can't hook event beforeSave of Model in this case. Please tell me know how i can do it ?
I have tested everything work find on PUT. (loopback v2.9.1)
module.exports = function(Blog) {
Blog.beforeSave = function(next,data)
console.log('hello');
next()
}
}
Where can i get loopback v2.9.1 ?, in my app it's only 2.2.0
Sorry for mistake. you can check with
slc version
loopback 2.2.0 is correct.
slc update
Here is my result with slc version: strongloop v2.9.1 (node v0.10.32) ├── [email protected] ├─┬ [email protected] │ └── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]
Can you give me example about using beforeSave on PUT method ?
"blog.json"
{
"name": "Blog",
"plural": "Blogs",
"base": "PersistedModel",
"strict": false,
"idInjection": false,
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
"blog.js"
module.exports = function(Blog) {
Blog.beforeSave = function(next,data){
console.log('hello');
next()
}
};
I got console.log print out when call PUT /Blogs/{pk} PUT /Blogs
i put a console.log('aa') on function beforeSave() but don't get any text show on my console when i request PUT method to server. Please give me a complete example that implement this case. Thanks a lot.
slc loopback:model
[?] Enter the model name: Joker
[?] Select the data-source to attach Joker to: db (memory)
[?] Expose Joker via the REST API? Yes
[?] Custom plural form (used to build REST URL):
Let's add some Joker properties now.
Enter an empty property name when done.
[?] Property name:
then you got "joker.json" , "joker.js" edit "joker.js"
module.exports = function(Joker) {
Joker.beforeSave = function(next,data){
console.log(data)
console.log('Hello Joker');
next()
}
};
Call (I use loopback explorer) PUT /Jokers
{
"name" : "joker I"
}
It works fine.
Here my ss http://postimg.org/image/q63pr8l9b/
I recreate new Model as you comment it work fine but it doesn't work when you create Model with property name is "location".
{ "name": "Store", "plural": "Stores", "base": "PersistedModel", "properties": { "name": { "type": "string", "length": 50, "required": true }, "location": { "type": "geopoint", "required": true }, "picture": { "type": "string" } }, "validations": [], "relations": {}, "acls": [], "methods": [] }
You can try to create a new model with upper structure and you can see this bug.
I have no problem. Here ss http://postimg.org/image/dl719rlu7/
the problem doesn't happen anymore after I restarted my computer - Ubuntu 12.04.5 LTS O.o
thanks for ur support :">