How can I clone a Parse Query using the Javascript

2019-09-06 19:52发布

I want to clone queries because it helps me structure my code better. But, when I try to clone an query, I get an error saying: Object [object Object] has no method 'skip'. Here's the code I've tried:

var _ = require('cloud/modules/lodash'); // custom lodash 4.0.0
...
var query = new Query('Class');

var clonedQuery = _.clone(query);        // .cloneDeep() doesn't work either
clonedQuery.skip(i);                     // succeeds in unit tests but fails on cloud code
var clonedQuery.first();

Note: The underscore _ is actually lodash 4.0.0 that I've manually bundled with my source code, not the cloud module from Parse.

It's not clear to my why this is failing — it's lodash doing the cloning here, so there should be no difference between my local unit testing node environment and the V8 Cloud Code environment.


EDIT: I was using Parse SDK 1.3.1 here. Solution is to upgrade. See below.

1条回答
相关推荐>>
2楼-- · 2019-09-06 20:42

_.clone() actually does work for Query in Parse SDK 1.6.14, but not on 1.3.1, which I was using. I didn't know that you can manage the Parse JS SDK version yourself using the parse jssdk tool!

The solution for me was simply to update the SDK. See the discussion here: https://github.com/ParsePlatform/Parse-SDK-JS/issues/171

查看更多
登录 后发表回答