我有一对派生自ParseObject,DbRound和DbLocation的类。 DbRound有一个名为" Location"指向DbLocation。我创建一个查询并包含("位置")希望在我获取DbRound时获取引用的DbLocation;没有快乐。但是,我可以在后续的提取操作中获取位置。
我的目标是在单个查询中同时获取DbRound和引用的DbLocation。我误解了ParseQuery.Include()的意图,还是错误地使用它?或者我完全以错误的方式解决这个问题?
这在Unity中运行。以下是相关代码:
IEnumerator CheckRound( string roundId )
{
// DbRound.Location is a pointer to DbLocation (a ParseObject derivative)
var query = new ParseQuery< DbRound >();
query.Include( "Location" );
var task = query.GetAsync( roundId );
while( !task.IsCompleted ) yield return new WaitForEndOfFrame();
if( ! task.IsFaulted )
{
// task.Result.Location contains a default-constructed DbLocation
Debug.Log( "task.Result.Location.IsDataAvailable: " +
task.Result.Location.IsDataAvailable );
var rel = new List< ParseObject > { task.Result.Location };
var t = ParseObject.FetchAllIfNeededAsync( rel );
while( ! t.IsCompleted ) yield return new WaitForEndOfFrame();
// now task.Result.Location has a value of the referenced DbLocation
Debug.Log( "task.Result.Location.IsDataAvailable: " +
task.Result.Location.IsDataAvailable );
DisplayRound( task.Result );
}
}
记录结果:
12/28/2015 18:30:00.4214 task.Result.Location.IsDataAvailable: False
12/28/2015 18:30:10.7530 task.Result.Location.IsDataAvailable: True
TIA, --Joshua
[编辑:按要求,添加来源]
首先,是什么推动了演示:
IEnumerator SetUpBugDemo()
{
var location = new DbLocation( "A desolate place" );
yield return StartCoroutine( Store( location ) );
var round = new DbRound( location );
yield return StartCoroutine( Store( round ) );
yield return StartCoroutine( CheckRound( round.ObjectId ) );
}
IEnumerator Store( DbLocation location )
{
var task = location.SaveAsync();
while( !task.IsCompleted ) { yield return new WaitForEndOfFrame(); }
}
IEnumerator Store( DbBogusRound round )
{
var task = round.SaveAsync();
while( !task.IsCompleted ) { yield return new WaitForEndOfFrame(); }
}
现在派生的ParseObject声明:
[ParseClassName( "Location" )]
public class DbLocation : ParseObject
{
[ParseFieldName( "Text" )]
public string Text
{
get { return GetProperty< string >( "Text" ); }
set { SetProperty< string >( value, "Text" ); }
}
[ParseFieldName( "HashTag" )]
public string HashTag
{
get { return GetProperty< string >( "HashTag" ); }
set { SetProperty< string >( value, "HashTag" ); }
}
[ParseFieldName( "BreakdownValue" )]
public int BreakdownValue
{
get { return GetProperty< int >( "BreakdownValue" ); }
set { SetProperty< int >( value, "BreakdownValue" ); }
}
[ParseFieldName( "CreationValue" )]
public int CreationValue
{
get { return GetProperty< int >( "CreationValue" ); }
set { SetProperty< int >( value, "CreationValue" ); }
}
public DbLocation( string text )
{
Text = text;
HashTag = "<none>";
BreakdownValue = 0;
CreationValue = 0;
}
public DbLocation()
{ /* required for Parse */}
}
[ParseClassName( "Round" )]
public class DbRound : ParseObject
{
[ParseFieldName( "Location" )]
public DbLocation Location
{
get { return GetProperty< DbLocation >( "Location" ); }
set
{
var locationRef =
ParseObject.CreateWithoutData<DbLocation>( value.ObjectId );
SetProperty( locationRef, "Location" );
}
}
public DbRound( DbLocation location )
{
Location = location;
}
public DbRound()
{ /* required for Parse */ }
}
[编辑:添加Parse API控制台输出]
上面的示例代码中有一个Round和Location实例。
GET classes/Round
RESPONSE
{
"results": [
{
"Location": {
"__type": "Pointer",
"className": "Location",
"objectId": "YuJlyxhRSe"
},
"createdAt": "2015-12-29T22:53:59.966Z",
"objectId": "ugg61jLPN6",
"updatedAt": "2015-12-29T22:53:59.966Z"
}
]
}
GET classes/Location
RESPONSE
{
"results": [
{
"BreakdownValue": 0,
"CreationValue": 0,
"HashTag": "<none>",
"Text": "A desolate place",
"createdAt": "2015-12-29T22:53:59.319Z",
"objectId": "YuJlyxhRSe",
"updatedAt": "2015-12-29T22:53:59.319Z"
}
]
}
答案 0 :(得分:0)
setx /m path %PATH%%~dp0
然后查询按预期返回Location的数据。