简体   繁体   English

在Parse Cloud代码中使用指针无法查询

[英]Query with pointers not working, in Parse Cloud code

Here is some Parse Cloud code I have running: 这是我正在运行的一些Parse Cloud代码:

…….
var sentenceListQuery;
sentenceListQuery = new Parse.Query("SentenceList");
sentenceListQuery.equalTo("unit", request.params.unitID); // May be wrong!
sentenceListQuery.find
({…….});

unit is a column of type: Pointer unit是以下类型的列:指针

  • If I get rid of the line marked “May be wrong!”, by commenting it out, I get 83 as the number of rows found by the .find() , which is what I expect. 如果我摆脱掉标记为“可能是错误的!”的行,通过注释掉它,我得到了.find()找到的行数为83,这是我所期望的。

  • If I leave it there I get zero lines, which is not what I expect. 如果我把它留在那里,我会得到零行,这不是我期望的。 I should get one line. 我应该打一行。

So my guess is that something is not right with the way I write the code on this line, but I don't know what. 所以我的猜测是,我在此行上编写代码的方式有问题,但我不知道是什么。 Should I use a different syntax because it is a pointer? 我是否应该使用其他语法,因为它是一个指针? I found a few seemingly related things on the net, but nothing driving me to a working solution. 我在网上发现了一些看似相关的东西,但没有任何东西促使我找到可行的解决方案。 Or would it be that relationships on Parse.com are more difficult to use than it should; 还是因为Parse.com上的关系比应使用的关系难使用? and one should avoid using them? 并且应该避免使用它们? In fact getting the same result without relationships would be rather easy; 实际上,在没有关系的情况下获得相同的结果将非常容易。 I just thought it was better practice to use them. 我只是认为使用它们是更好的做法。

You have to write a pointer as an object. 您必须将指针写为对象。 Useful example: 有用的例子:

 var unitPointer = {"__type":"Pointer","className":"Unit","objectId":request.params.unitID};    
 sentenceListQuery.equalTo("unit", unitPointer); // Should be right

The above example assumes the name of the Class you are pointing to is "Unit". 上面的示例假定您指向的类的名称为“ Unit”。

If applicable, you could replace your unitID parameter with some pointer in the request.object or request.user your Cloud Code is already processing. 如果适用,您可以将您的unitID参数替换为request.object或request.user中的某个指针,您的云代码已在处理中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM