-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting [Object object] instead of an id #40
Comments
Hi @ajkaanbal, a few things:
|
And BTW, it's more likely the error is somewhere in replaceKeyForId(model, key) which is called just before line 70. |
Hi @dmarcelino
waterline-orientdb:connection:debug DEBUG OrientDB query: SELECT *, @rid, createdAt, updatedAt, out_profileconnection FROM profile LIMIT 30 SKIP 0 +4s
waterline-orientdb:connection:debug DEBUG params: [object Object]
Inspected object:
{ params: {} } +0ms
waterline-orientdb:connection:debug DEBUG opts.fetchPlan: out_profileconnection:1 out_profileconnection.in:1 +0ms |
I also thought that it was there but didn't find how to make it work. I did this (comment the delete and remove the else condition): if(hop.call(model, 'rid')) {
// case where the @rid is a temporary one
self.replaceKeyForId(model, 'rid');
/// delete model['@rid'];
}
if(hop.call(model, '@rid')) {
self.replaceKeyForId(model, '@rid');
} It works but broke the tests |
In that case you would get a Can you try adding a exports.replaceKeyForId = function replaceKeyForId(model, key) {
// change id to string only if it's necessary
var modelId;
console.log(typeof model[key], model[key]); // add this line
if(typeof model[key] === 'object')
modelId = model[key].toString();
else
modelId = model[key];
if(modelId.indexOf('#-') !== 0){ // ignoring temporary ids
model.id = modelId;
}
delete model[key];
}; |
waterline-orientdb:connection:debug DEBUG OrientDB query: SELECT *, @rid, createdAt, updatedAt, out_profileconnection FROM profile LIMIT 30 SKIP 0 +7s
waterline-orientdb:connection:debug DEBUG params: [object Object]
Inspected object:
{ params: {} } +1ms
waterline-orientdb:connection:debug DEBUG opts.fetchPlan: out_profileconnection:1 out_profileconnection.in:1 +0ms
object { '@type': 'document',
'@class': 'profile',
profiletype: 'Person',
name: 'Juan',
alias: 'juanito',
birthday: '1-01-1980',
deathday: '12-12-2010',
nationality: 'Francesa',
professions: 'Músico',
profiles: [ { cluster: 3, position: 53 } ],
createdAt: Tue Feb 17 2015 10:03:48 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 10:03:48 GMT-0600 (CST),
out_profileconnection:
{ '@type': 'd',
'@class': 'profileconnection',
out: [Circular],
in:
{ '@type': 'd',
'@class': 'subprofile',
createdAt: Tue Feb 17 2015 10:03:48 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 10:03:48 GMT-0600 (CST),
in_profileconnection: [Circular],
'@rid': [Object] },
'@rid': { cluster: 17, position: 0 } },
rid: [Circular],
'@rid': { cluster: 16, position: 0 } }
object { cluster: 17, position: 0 }
object { cluster: 21, position: 0 }
object { '@type': 'd',
'@class': 'profile',
profiletype: 'people',
name: 'Juan',
createdAt: Tue Feb 17 2015 12:06:25 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 12:06:25 GMT-0600 (CST),
rid: [Circular],
'@rid': { cluster: 16, position: 1 } }
object { '@type': 'd',
'@class': 'profile',
profiletype: 'people',
name: 'Glennie Marks V',
alias: 'Arianna_Spinka31',
birthday: '2-02-2015',
deathday: '1-02-2014',
nationality: 'Thailand',
createdAt: Tue Feb 17 2015 13:18:53 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 13:18:53 GMT-0600 (CST),
rid: [Circular],
'@rid': { cluster: 16, position: 2 } }
object { '@type': 'd',
'@class': 'profile',
profiletype: 'people',
name: 'Julio Cantú I',
alias: 'MaríadelCarmen.Araña0',
birthday: '2-02-2015',
deathday: '1-02-2015',
nationality: 'Moldavia',
createdAt: Tue Feb 17 2015 13:37:31 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 13:37:31 GMT-0600 (CST),
rid: [Circular],
'@rid': { cluster: 16, position: 3 } } |
I wasn't expecting that 😄 , is that the output of |
@ajkaanbal, I was able to reproduce the issue, it seems the hack |
Yes, for that model I need schemaless. |
Issue #40: allows schemaless objects to be retrieved using '*'
I've pushed a fix to |
I'm using sails, and something was wrong. I add a console.log in line 40 (like before) and 68. waterline-orientdb:connection:debug DEBUG OrientDB query: SELECT *, @rid, createdAt, updatedAt, out_profileconnection FROM profile LIMIT 30 SKIP 0 +2s
waterline-orientdb:connection:debug DEBUG params: [object Object]
Inspected object:
{ params: {} } +0ms
waterline-orientdb:connection:debug DEBUG opts.fetchPlan: out_profileconnection:1 out_profileconnection.in:1 +0ms
model { '@type': 'document',
'@class': 'profile',
profiletype: 'Person',
name: 'Juan',
alias: 'juanito',
birthday: '1-01-1980',
deathday: '12-12-2010',
nationality: 'Francesa',
professions: 'Músico',
profiles: [ { cluster: 3, position: 54 } ],
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
out_profileconnection:
{ '@type': 'd',
'@class': 'profileconnection',
out: [Circular],
in:
{ '@type': 'd',
'@class': 'subprofile',
profiletype: 'Musician',
band: 'Nombre de la banda',
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
in_profileconnection: [Circular],
'@rid': [Object] },
'@rid': { cluster: 17, position: 0 } },
rid: [Circular],
'@rid': { cluster: 16, position: 0 } }
object { cluster: 16, position: 0 }
model { '@type': 'd',
'@class': 'profileconnection',
out:
{ '@type': 'document',
'@class': 'profile',
profiletype: 'Person',
name: 'Juan',
alias: 'juanito',
birthday: '1-01-1980',
deathday: '12-12-2010',
nationality: 'Francesa',
professions: 'Músico',
profiles: [ [Object] ],
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
out_profileconnection: [Circular],
rid: [Circular],
id: '#16:0' },
in:
{ '@type': 'd',
'@class': 'subprofile',
profiletype: 'Musician',
band: 'Nombre de la banda',
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
in_profileconnection: [Circular],
'@rid': { cluster: 21, position: 0 } },
'@rid': { cluster: 17, position: 0 } }
object { cluster: 17, position: 0 }
model { '@type': 'd',
'@class': 'subprofile',
profiletype: 'Musician',
band: 'Nombre de la banda',
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
in_profileconnection:
{ '@type': 'd',
'@class': 'profileconnection',
out:
{ '@type': 'document',
'@class': 'profile',
profiletype: 'Person',
name: 'Juan',
alias: 'juanito',
birthday: '1-01-1980',
deathday: '12-12-2010',
nationality: 'Francesa',
professions: 'Músico',
profiles: [Object],
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
out_profileconnection: [Circular],
rid: [Circular],
id: '#16:0' },
in: [Circular],
id: '#17:0' },
'@rid': { cluster: 21, position: 0 } }
object { cluster: 21, position: 0 }
model { cluster: 3, position: 54 }
model { '@type': 'd',
'@class': 'subprofile',
profiletype: 'Musician',
band: 'Nombre de la banda',
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
in_profileconnection:
{ '@type': 'd',
'@class': 'profileconnection',
out:
{ '@type': 'document',
'@class': 'profile',
profiletype: 'Person',
name: 'Juan',
alias: 'juanito',
birthday: '1-01-1980',
deathday: '12-12-2010',
nationality: 'Francesa',
professions: 'Músico',
profiles: [Object],
createdAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
updatedAt: Tue Feb 17 2015 17:06:28 GMT-0600 (CST),
rid: [Circular],
id: '#16:0' },
in: [Circular],
id: '#17:0' },
id: '#21:0' }
silly: res.ok() :: Sending 200 ("OK") response
Unhandled rejection TypeError: Converting circular structure to JSON
at Object.stringify (native)
at ServerResponse.res.json (/opt/node_modules/sails/node_modules/express/lib/response.js:189:19)
at ServerResponse.jsonx (/opt/node_modules/sails/lib/hooks/responses/index.js:217:21)
at Object.sendOK (/opt/api/responses/ok.js:28:16)
at ServerResponse.bound [as ok] (/opt/node_modules/lodash/dist/lodash.js:729:21)
at found (/opt/node_modules/sails/lib/hooks/blueprints/actions/find.js:64:9)
at bound (/opt/node_modules/lodash/dist/lodash.js:957:21)
at applyInOriginalCtx (/opt/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:416:80)
at wrappedCallback (/opt/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:315:18)
at _normalizeCallback.callback.success (/opt/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:33:31)
at _switch (/opt/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:48:28)
at returnResults (/opt/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:356:9)
at /opt/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:256:16
at /opt/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:77:45
at bound (/opt/node_modules/lodash/dist/lodash.js:957:21)
at applyInOriginalCtx (/opt/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:416:80)
at wrappedCallback (/opt/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:315:18)
at _normalizeCallback.callback.success (/opt/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:33:31)
at _switch (/opt/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:48:28)
at /opt/node_modules/waterline-orientdb/lib/associations.js:220:3
at Db.<anonymous> (/opt/node_modules/waterline-orientdb/lib/connection.js:470:11)
From previous event:
at module.exports.DbHelper.find (/opt/node_modules/waterline-orientdb/lib/connection.js:467:8)
at Associations.fetchPlanJoin (/opt/node_modules/waterline-orientdb/lib/associations.js:156:19)
at Associations.join (/opt/node_modules/waterline-orientdb/lib/associations.js:40:17)
at Object.module.exports.adapter.join (/opt/node_modules/waterline-orientdb/lib/adapter.js:258:27)
at module.exports.join (/opt/node_modules/sails/node_modules/waterline/lib/waterline/adapter/dql.js:53:13)
at _runOperation (/opt/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:400:29)
at run (/opt/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:69:8)
at bound.module.exports.find (/opt/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:243:16)
at bound [as find] (/opt/node_modules/lodash/dist/lodash.js:729:21)
at Deferred.exec (/opt/node_modules/sails/node_modules/waterline/lib/waterline/query/deferred.js:501:16)
at findRecords (/opt/node_modules/sails/lib/hooks/blueprints/actions/find.js:50:9)
at routeTargetFnWrapper (/opt/node_modules/sails/lib/router/bind.js:178:5)
at callbacks (/opt/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/opt/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/opt/node_modules/sails/node_modules/express/lib/router/index.js:145:5)
at nextRoute (/opt/node_modules/sails/node_modules/express/lib/router/index.js:100:7)
at callbacks (/opt/node_modules/sails/node_modules/express/lib/router/index.js:167:11)
at /opt/node_modules/sails/lib/router/bind.js:186:7
at alwaysAllow (/opt/node_modules/sails/lib/hooks/policies/index.js:209:11)
at routeTargetFnWrapper (/opt/node_modules/sails/lib/router/bind.js:178:5)
at callbacks (/opt/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/opt/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/opt/node_modules/sails/node_modules/express/lib/router/index.js:145:5)
at nextRoute (/opt/node_modules/sails/node_modules/express/lib/router/index.js:100:7)
at callbacks (/opt/node_modules/sails/node_modules/express/lib/router/index.js:167:11)
|
That suggests that the object returned contains circular references and it fails to convert to json. In your code, after getting the record from the database, can you try using removeCircularReferences()? For example: Profile.removeCircularReferences(profiles, function(result){
// result won't have circular references, so it's safe to use.
}); |
ok, adding the removeCircularReference resolves the issue with sails. {
"alias": "juanito",
"birthday": "1-01-1980",
"createdAt": "2015-02-18T00:15:43.000Z",
"deathday": "12-12-2010",
"id": "#16:1",
"name": "Juan",
"nationality": "Francesa",
"professions": "Músico",
"profiles": [
{
"band": "Nombre de la banda",
"createdAt": "2015-02-18T00:15:43.000Z",
"id": "#21:1",
"profiletype": "Musician",
"updatedAt": "2015-02-18T00:15:43.000Z"
}
],
"profiletype": "Person",
"rid": {
"alias": "juanito",
"birthday": "1-01-1980",
"createdAt": "2015-02-18T00:15:43.000Z",
"deathday": "12-12-2010",
"id": "#16:1",
"name": "Juan",
"nationality": "Francesa",
"professions": "Músico",
"profiles": [
{
"band": "Nombre de la banda",
"createdAt": "2015-02-18T00:15:43.000Z",
"id": "#21:1",
"profiletype": "Musician",
"updatedAt": "2015-02-18T00:15:43.000Z"
}
],
"profiletype": "Person",
"rid": "#16:1",
"updatedAt": "2015-02-18T00:15:43.000Z"
},
"updatedAt": "2015-02-18T00:15:43.000Z"
} |
Good to hear that! In the future I'll look into improving schemaless support as I don't think that |
…ueries (when collection is schemaless) Relates to #40
I have these models
Profile.js
Subprofile.js
profileconnection
And the result is
I found that is in the function rewriteIds file lib/utils.js line 70 but I don't understand why.
The text was updated successfully, but these errors were encountered: