1

当我想从包含 ParseRelation 的子类中检索 ParseObjects 时遇到问题

当此代码运行时:

public void loadProjectsForCurrentUser() {
    User currUser = UserManager.Instance.CurrentUser;
    if (currUser != null) {
        currUser.Projects.Query.FindAsync().ContinueWith(t => {
            if(onProjectsLoaded != null) {
                onProjectsLoaded(new List<Project>(t.Result));
            }
        });
    } else {
        Debug.LogWarning("Trying to load projects while not logged in!");
    }
}

我收到此错误:

错误消息:创建 ParseQuery 时必须指定 ParseObject 类名。参数名称:类名

这是我的子类的一部分:

[ParseFieldName(PARSE_VALUES.Projects)]
[CoherentProperty]
public ParseRelation<Project> Projects {
    get { return GetRelationProperty<Project>("Projects"); }
}

当用户登录时,我创建了一个新的用户实例,并获取如下数据:

User currUser = ParseUser.CreateWithoutData<User>(ParseUser.CurrentUser.ObjectId);
currUser.FetchIfNeededAsync().ContinueWith(userResult => {
  Debug.Log("Fetched User");
  currUser.Company.FetchIfNeededAsync().ContinueWith(companyResult => {
    Debug.Log("Fetched Company");
    UserManager.Instance.CurrentUser = currUser;
    ParentView.TriggerEvent("login", UserManager.Instance.CurrentUser);
    ProjectManager.Instance.loadProjectsForCurrentUser();
    if (onLogin != null)
        onLogin();
  });
});

我已经找到了这个页面: https ://www.parse.com/questions/error-when-querying-relational-data-in-unity

这是堆栈跟踪,可能包含有趣的信息:

错误消息:创建 ParseQuery 时必须指定 ParseObject 类名。参数名称:className Stack Trace: at Parse.ParseQuery 1<Project>..ctor (string) <0x0008f> at Parse.ParseRelationBase.GetQuery<Project> () <0x0004e> at Parse.ParseRelation1.get_Query () <0x00039> at (wrapper dynamic-method) Parse.ParseRelation 1<Project>.GetProperty (Parse.ParseRelation1&,Coherent.UI.Binding.Exporter) at Coherent.UI.Binding.UserDefinedTypeExporter 1<Parse.ParseRelation1>。导出 (Coherent.UI.Binding.Exporter,Parse.ParseRelation 1<Project>) <0x00145> at Coherent.UI.Binding.Exporter.Export<Parse.ParseRelation1> (Parse.ParseRelation 1.Export 1<Project>) <0x00404> at (wrapper dynamic-method) User.GetProperty (User&,Coherent.UI.Binding.Exporter) <IL 0x00008, 0x00048> at Coherent.UI.Binding.UserDefinedTypeExporter(Coherent.UI.Binding.Exporter,User) <0x00145> 在 Coherent.UI.Binding.Exporter.Export (User) < 0x00404> 在 Coherent.UI.Binding.UserDefinedTypeExporter 处(包装器动态方法)Project.GetProperty (Project&,Coherent.UI.Binding.Exporter)1<Project>.Export (Coherent.UI.Binding.Exporter,Project) <0x00145> at Coherent.UI.Binding.Exporter.Export<Project> (Project) <0x00404> at Coherent.UI.Binding.Exporter.ExportIList<Project> (Coherent.UI.Binding.Exporter,System.Collections.Generic.IList1)<0x00142>在(包装动态方法)Coherent.UI.Binding.Exporter.Exporter(Coherent.UI.Binding.Exporter,System.Collections.Generic.List 1<Project>) <IL 0x00002, 0x0002c> at Coherent.UI.Binding.Exporter.Export<System.Collections.Generic.List1>(System.Collections.Generic.List 1<Project>) <0x00404> at Coherent.UI.Binding.ViewExtensions.TriggerEvent<System.Collections.Generic.List1>( Coherent.UI.View,string,System.Collections.Generic.List 1<Project>) <0x00073> at ProjectsWidget.onProjectsLoaded (System.Collections.Generic.List1) [0x0000c] 在

但我似乎找不到错误......任何可以帮助的人?

4

1 回答 1

2

最终自己找到了。

它是 Coherent 和 Parse 之间问题的组合。Coherent 尝试使用 ParseRelation 的默认构造函数,我在 User 类中将其用作属性。但是 ParseRelation 没有默认构造函数。

Coherent 确实需要一个默认构造函数。我更改了以下内容:

[ParseFieldName(PARSE_VALUES.Projects)]
[CoherentProperty]
public ParseRelation<Project> Projects {
    get { return GetRelationProperty<Project>("Projects"); }
}

进入

[ParseFieldName(PARSE_VALUES.Projects)]
public ParseRelation<Project> Projects {
    get { return GetRelationProperty<Project>("Projects"); }
}

通过删除我最终不需要的 CoherentProperty 标签,Coherent 不想导出 ParseRelation,因此我不再有构造函数错误!

于 2014-09-28T08:48:24.997 回答