当我想从包含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类名。 参数名称:className
这是我的子类的一部分:
[ParseFieldName(PARSE_VALUES.Projects)]
[CoherentProperty]
public ParseRelation<Project> Projects {
get { return GetRelationProperty<Project>("Projects"); }
}
当用户登录时,我创建了一个新的User实例,我就像这样获取数据:
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
这是堆栈跟踪,可能包含有趣的信息:
错误消息:创建时必须指定ParseObject类名 ParseQuery。参数名称:className Stack Trace:at Parse.ParseQuery
1<Project>..ctor (string) <0x0008f> at Parse.ParseRelationBase.GetQuery<Project> () <0x0004e> at Parse.ParseRelation
1.get_Query()&lt; 0x00039&gt;在(包装 动态方法)Parse.ParseRelation1<Project>.GetProperty (Parse.ParseRelation
1&amp;,Coherent.UI.Binding.Exporter)at Coherent.UI.Binding.UserDefinedTypeExporter1<Parse.ParseRelation
1&GT;。出口 (Coherent.UI.Binding.Exporter,Parse.ParseRelation1<Project>) <0x00145> at Coherent.UI.Binding.Exporter.Export<Parse.ParseRelation
1&GT; (Parse.ParseRelation1<Project>) <0x00404> at (wrapper dynamic-method) User.GetProperty (User&,Coherent.UI.Binding.Exporter) <IL 0x00008, 0x00048> at Coherent.UI.Binding.UserDefinedTypeExporter
1.Export (Coherent.UI.Binding.Exporter,User)&lt; 0x00145&gt;在 Coherent.UI.Binding.Exporter.Export(User)&lt; 0x00404&gt;在(包装 动态方法)Project.GetProperty (Project&amp;,Coherent.UI.Binding.Exporter)at Coherent.UI.Binding.UserDefinedTypeExporter1<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.IList
1) &LT; 0x00142&GT; at(包装器动态方法) Coherent.UI.Binding.Exporter.Exporter (Coherent.UI.Binding.Exporter,System.Collections.Generic.List1<Project>) <IL 0x00002, 0x0002c> at Coherent.UI.Binding.Exporter.Export<System.Collections.Generic.List
1&GT; (System.Collections.Generic.List1<Project>) <0x00404> at Coherent.UI.Binding.ViewExtensions.TriggerEvent<System.Collections.Generic.List
1&GT; (Coherent.UI.View,string,System.Collections.Generic.List1<Project>) <0x00073> at ProjectsWidget.onProjectsLoaded (System.Collections.Generic.List
1)[0x0000c] in
但我似乎无法找到错误...... 有人可以提供帮助吗?
答案 0 :(得分: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,因此我不再有构造函数错误了!