Skip to content

Commit

Permalink
RavenDB-769 Issue with SelectMany() in index map
Browse files Browse the repository at this point in the history
  • Loading branch information
Fitzchak Yitzchaki committed Feb 7, 2013
1 parent 6bd0b9c commit 14836df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions Raven.Abstractions/Linq/DynamicJsonObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,16 @@ public object TransformToValue(RavenJToken jToken)
}

private RavenJObject FindReference(string refId)
{
return GetRootParentOrSelf().Scan().FirstOrDefault(x => x.Value<string>("$id") == refId);
}

public DynamicJsonObject GetRootParentOrSelf()
{
var p = this;
while (p.parent != null)
p = p.parent;

return p.Scan().FirstOrDefault(x => x.Value<string>("$id") == refId);
return p;
}

private IEnumerable<RavenJObject> Scan()
Expand Down Expand Up @@ -294,7 +298,7 @@ public object GetValue(string name)
{
if (name == Constants.DocumentIdFieldName)
{
return GetDocumentId();
return GetRootParentOrSelf().GetDocumentId();
}
RavenJToken value;
if (inner.TryGetValue(name, out value))
Expand All @@ -310,7 +314,7 @@ public object GetValue(string name)
}
if (name == "Id")
{
return GetDocumentId();
return GetRootParentOrSelf().GetDocumentId();
}
if (name == "Inner")
{
Expand Down
2 changes: 1 addition & 1 deletion Raven.Database/Indexing/SimpleIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private class IndexingResult

private IndexingResult ExtractIndexDataFromDocument(AnonymousObjectToLuceneDocumentConverter anonymousObjectToLuceneDocumentConverter, DynamicJsonObject dynamicJsonObject)
{
var newDocId = dynamicJsonObject.GetDocumentId();
var newDocId = dynamicJsonObject.GetRootParentOrSelf().GetDocumentId();
return new IndexingResult
{
Fields = anonymousObjectToLuceneDocumentConverter.Index(((IDynamicJsonObject)dynamicJsonObject).Inner, Field.Store.NO).ToList(),
Expand Down
6 changes: 5 additions & 1 deletion Raven.Tests/Linq/SelectManyShouldWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ public Creatives_ClickActions_2()
{
Map = snapshots => snapshots
.SelectMany(x => x.ClickActions)
.Select(x => new {ClickedBy = x.ContactId, x.CreativeId});
.Select(x => new
{
ClickedBy = new[] {x.ContactId},
x.CreativeId
});

Reduce = result => result
.GroupBy(x => x.CreativeId)
Expand Down

0 comments on commit 14836df

Please sign in to comment.