Skip to content

Adding extra includes from IResourceDefinition.OnApplyIncludes() does not work #989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bart-degreed opened this issue May 6, 2021 · 0 comments · Fixed by #1011
Closed
Assignees
Labels

Comments

@bart-degreed
Copy link
Contributor

Example:

public sealed class Engagement : EntityBase<Guid>
{
    [HasMany]
    public ICollection<EngagementParty> Parties { get; set; }
}

public sealed class EngagementParty : EntityBase<Guid>
{
}

public sealed class EngagementResourceDefinition : JsonApiResourceDefinition<Engagement, Guid>
{
    public EngagementResourceDefinition(IResourceGraph resourceGraph)
        : base(resourceGraph)
    {
    }

    public override IReadOnlyCollection<IncludeElementExpression> OnApplyIncludes(
        IReadOnlyCollection<IncludeElementExpression> existingIncludes)
    {
        ResourceContext engagementContext = ResourceGraph.GetResourceContext<Engagement>();

        RelationshipAttribute partiesRelationship = engagementContext.Relationships.Single(relationship
            => relationship.Property.Name == nameof(Engagement.Parties));

        HashSet<IncludeElementExpression> newIncludes = existingIncludes.ToHashSet();
        newIncludes.Add(new IncludeElementExpression(partiesRelationship));
        return newIncludes;
    }
}

The query gets composed and executed properly, but the serializer forgets to take additions from IResourceDefition<,>.OnApplyIncludes into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant