- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 158
Filter included relations #474
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
Comments
@medokin there are two issues here. The first is due to a design flaw in JADNC that we still need to resolve. Currently, when you include resources, this is done from the target resource service.
Any logic you've defined in the One option you have is to run your same filtering logic in the JsonApiDotNetCore/src/JsonApiDotNetCore/Services/EntityResourceService.cs Lines 231 to 238 in a1241ee
You might try:
The second issue (depending on what you're trying to do) is described here: aspnet/EntityFrameworkCore#1833 Support filtered Include. One alternative is to load transactions into memory and the perform the filtering, but this will not scale well. |
I mean doesnt this call for a more generic Access Control system? Something thats tied to the model and therefore gets implemented in every layer? This can stand on its own I guess. Just spitballin' here. Might look into this. |
Running the same logic /repeating yourself is of course not the proper way |
This has been solved with the introduction of resource hooks in v4. The proper way would now be to implement the public class TransactionResource : ResourceDefinition<Transaction>
{
public TransactionResource(IResourceGraph graph) : base(graph) { }
public override IEnumerable<Transaction> OnReturn(HashSet<Transaction> entities, ResourcePipeline pipeline)
{
return entities.Where(t => !t.ShouldHide);
}
} This hook will be fired in both cases:
For more information, see the docs for resource hooks. Docs are a little out of date, see #552 about that |
Description
Let's assume I have two entities.
A
Person
that has manyTransaction
. I've implemented aTransactionService
to hide some transactions from the user.Works great when querying
Transaction
, but when I query aPerson
withinclude=transactions
, it includes the hidden transactions.Am I missing something, or do I need to reimplement the filter in every relation of
Transaction
?Thanks for this great piece of software!
Environment
The text was updated successfully, but these errors were encountered: