Skip to content

Commit 46fbf74

Browse files
committed
allow meta to be included even if there is no returned resource
1 parent faa00b4 commit 46fbf74

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/JsonApiDotNetCore/Builders/DocumentBuilder.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,20 @@ public Documents Build(IEnumerable<IIdentifiable> entities)
6868

6969
private Dictionary<string, object> GetMeta(IIdentifiable entity)
7070
{
71-
if (entity == null) return null;
72-
7371
var builder = _jsonApiContext.MetaBuilder;
74-
75-
if (entity is IHasMeta metaEntity)
76-
builder.Add(metaEntity.GetMeta(_jsonApiContext));
77-
7872
if (_jsonApiContext.Options.IncludeTotalRecordCount && _jsonApiContext.PageManager.TotalRecords != null)
7973
builder.Add("total-records", _jsonApiContext.PageManager.TotalRecords);
8074

8175
if (_requestMeta != null)
8276
builder.Add(_requestMeta.GetMeta());
8377

78+
if (entity != null && entity is IHasMeta metaEntity)
79+
builder.Add(metaEntity.GetMeta(_jsonApiContext));
80+
8481
var meta = builder.Build();
85-
if (meta.Count > 0) return meta;
82+
if (meta.Count > 0)
83+
return meta;
84+
8685
return null;
8786
}
8887

0 commit comments

Comments
 (0)