Created
March 13, 2014 08:03
-
-
Save tauren/9523951 to your computer and use it in GitHub Desktop.
It seems that toJSON is being called on the results of another toJSON call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STEP 1 | |
npm install sails@beta -g | |
git clone [email protected]:coinprofit/sails-model-question.git | |
cd sails-model-question | |
npm init | |
sails lift | |
STEP 2 | |
Hit this URL in a browser: | |
http://localhost:1337/user/create?username=foo&password=foo&[email protected] | |
STEP 3 | |
Review server output. Note that in the 2nd call, the this object in toJSON() does not contain email or password. | |
In toJSON { username: 'foo', | |
password: 'foo', | |
email: '[email protected]', | |
createdAt: Thu Mar 13 2014 00:58:28 GMT-0700 (PDT), | |
updatedAt: Thu Mar 13 2014 00:58:28 GMT-0700 (PDT), | |
id: 1 } | |
In toJSON { username: 'foo', | |
createdAt: Thu Mar 13 2014 00:58:28 GMT-0700 (PDT), | |
updatedAt: Thu Mar 13 2014 00:58:28 GMT-0700 (PDT), | |
id: 1, | |
avatar: 'https://secure.gravatar.com/avatar/3717483f26171b61a4e2154fb37ffbd1?s=25&r=pg&d=mm' } | |
error: Server Error (500) | |
error: TypeError: Cannot call method 'toLowerCase' of undefined | |
at Object.module.exports.url (/Users/tauren/github/coinprofit/sails-model-question/node_modules/gravatar/lib/gravatar.js:10:62) | |
at module.exports.attributes.gravatarImage (/Users/tauren/github/coinprofit/sails-model-question/api/models/User.js:30:23) | |
at module.exports.attributes.toJSON (/Users/tauren/github/coinprofit/sails-model-question/api/models/User.js:36:26) | |
at Object.stringify (native) | |
at ServerResponse.res.json (/Users/tauren/github/coinprofit/sails-model-question/node_modules/sails/node_modules/express/lib/response.js:189:19) | |
at created (/Users/tauren/github/coinprofit/sails-model-question/node_modules/sails/lib/hooks/blueprints/actions/create.js:71:15) | |
at _normalizeCallback.callback.success (/Users/tauren/github/coinprofit/sails-model-question/node_modules/sails/node_modules/waterline/node_modules/node-switchback/lib/normalize.js:33:26) | |
at _switch (/Users/tauren/github/coinprofit/sails-model-question/node_modules/sails/node_modules/waterline/node_modules/node-switchback/lib/factory.js:34:26) | |
at /Users/tauren/github/coinprofit/sails-model-question/node_modules/sails/node_modules/waterline/lib/waterline/query/dql.js:106:11 | |
at /Users/tauren/github/coinprofit/sails-model-question/node_modules/sails/node_modules/async/lib/async.js:142:25 | |
I've got the same problem. If your user model is contained in another model, the other model should overwrite toJSON too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, I've encountered the same problem. Did you find a fix or a workaround? Thanks in advance.