Description
In an afterSave trigger I get an attribute that is ParseObject request.object.get('pointerToOtherParseObject').
I then use that object in a query and get this error: You cannot use [object Object] as a query parameter.
If I convert the object that was an attribute to the triggered object to a new ParseObject everything works as normal.
On the Parse.com hosted service I can use these attributes for performing a query.
Steps to reproduce
Please include a detailed list of steps that reproduce the issue. Include curl commands when applicable.
Trigger Setup
- Create an afterSave trigger function for "Comment".
- In the function get an attribute that is a Pointer to another ParseObject ("Post")
- Use that Object in an query.
Parse.Cloud.afterSave("Comment", function(request) {
var post = request.object.get("post");
var query = new Parse.Query("DailyPostCommentCount");
query.equalTo("dayInt",20160607);
console.log(post);
query.equalTo("post",post);
query.first().then(function(commentCount) {
console.log("successfully found the object that we want to update");
commentCount.increment("count");
return commentCount.save();
}).then(function(savedCommentCount) {
console.log("saved comment count");
},function(error) {
console.log("failed to find the object and update it with error:");
console.log(error);
});
});
Environment Setup
- Use Rest API to create a 'Post'
- Use Rest API to create a 'DailyPostCommentCount'
curl -X POST \
-H "X-Parse-Application-Id: <appId>" \
-H "X-Parse-REST-API-Key: , <RestKey>" \
-H "Content-Type: application/json" \
-d '{"title":"I am Hungry","content":"Where should we go for lunch"}' \
http://localhost:1337/parse/classes/Post
curl -X POST \
-H "X-Parse-Application-Id: <appId>" \
-H "X-Parse-REST-API-Key: <RestKey>" \
-H "Content-Type: application/json" \
-d '{"dayInt":20160607,"post":{"__type":"Pointer","className":"Post","objectId":"objecIdFromFirstRestCall"}}' \
http://localhost:1337/parse/classes/DailyPostCommentCount
Hitting the trigger
- Use Rest API to create a 'Comment' and trigger afterSave Function
curl -X POST \
-H "X-Parse-Application-Id: <appId>" \
-H "X-Parse-REST-API-Key: <RestKey>" \
-H "Content-Type: application/json" \
-d '{"content":"How about Sushirrito", "post":{"__type":"Pointer","className":"Post","objectId":"objecIdFromFirstRestCall"}}' \
http://localhost:1337/parse/classes/Comment
Expected Results
THe DailyPostCommentCount to increment 'count' counter.
Actual Outcome
ParseObject { _objCount: 1, className: 'Post', id: 'EJz6jexLbL' }
failed to find the object and update it with error:
ParseError {
code: 107,
message: 'You cannot use [object Object] as a query parameter.' }
If I convert the object to new ParseObject of the correct class everything works as normal:
exports.parseObjectFromParseDictObject = function(dict) {
var ObjectClass = Parse.Object.extend(dict.className);
var newObject = new ObjectClass();
newObject.id = dict.id;
return newObject;
}
Environment Setup
-
Server
- parse-server version: 2.2.11
- Operating System: OSX El Capitan
- Hardware: MacBook Pro
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Localhost
Same result when tried on Heroku
-
Database
- MongoDB version: 3.0.9
- Storage engine: MMAP
- Hardware: ?
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): ObjectRocket
Logs/Trace
You can turn on additional logging by configuring VERBOSE=1 in your environment.
10:11:01 web.1 | verbose: POST /parse/classes/Comment { host: 'localhost:1337',
10:11:01 web.1 | 'user-agent': 'curl/7.43.0',
10:11:01 web.1 | accept: '*/*',
10:11:01 web.1 | 'x-parse-application-id': 'adsfasdf',
10:11:01 web.1 | 'x-parse-rest-api-key': 'asdfas',
10:11:01 web.1 | 'content-type': 'application/json',
10:11:01 web.1 | 'content-length': '106' } {
10:11:01 web.1 | "content": "How about Sushirrito",
10:11:01 web.1 | "post": {
10:11:01 web.1 | "__type": "Pointer",
10:11:01 web.1 | "className": "Post",
10:11:01 web.1 | "objectId": "EJz6jexLbL"
10:11:01 web.1 | }
10:11:01 web.1 | }
10:11:02 web.1 | ParseObject { _objCount: 1, className: 'Post', id: 'EJz6jexLbL' }
10:11:02 web.1 | verbose: {
10:11:02 web.1 | "status": 201,
10:11:02 web.1 | "response": {
10:11:02 web.1 | "objectId": "ntAEASQLm7",
10:11:02 web.1 | "createdAt": "2016-06-07T16:11:01.580Z"
10:11:02 web.1 | },
10:11:02 web.1 | "location": "http://localhost:1337/parse/classes/Comment/ntAEASQLm7"
10:11:02 web.1 | }
10:11:02 web.1 | verbose: GET /parse/classes/DailyPostCommentCount { 'user-agent': 'node-XMLHttpRequest, Parse/js1.6.14 (NodeJS 4.4.0)',
10:11:02 web.1 | accept: '*/*',
10:11:02 web.1 | 'content-type': 'text/plain',
10:11:02 web.1 | host: 'localhost:1337',
10:11:02 web.1 | 'content-length': '320',
10:11:02 web.1 | connection: 'close' } {
10:11:02 web.1 | "where": {
10:11:02 web.1 | "dayInt": 20160607,
10:11:02 web.1 | "post": {
10:11:02 web.1 | "_objCount": 1,
10:11:02 web.1 | "className": "Post",
10:11:02 web.1 | "id": "EJz6jexLbL"
10:11:02 web.1 | }
10:11:02 web.1 | },
10:11:02 web.1 | "limit": 1
10:11:02 web.1 | }
10:11:02 web.1 | verbose: error: code=107, message=You cannot use [object Object] as a query parameter.
10:11:02 web.1 | failed to find the object and update it with error:
10:11:02 web.1 | ParseError {
10:11:02 web.1 | code: 107,
10:11:02 web.1 | message: 'You cannot use [object Object] as a query parameter.' }