-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
How to use legacy filter to get nested result #1666
Comments
Legacy filters are always applied to the resource type being requested (so
The Is there any reason you want to keep using legacy syntax? |
The core problem is this: https://localhost:7070/api/Authors?include=books&filter[books.desc]=eq:some could mean:
The syntax is ambiguous. |
@bkoelmanFirst of all, I appreciate your response. Here are the points: We need authors whose books contain a description with the value "abc". Database Screenshot Steps to Access the Filter - https://localhost:7070/api/Authors/1?include=books Step 1: Access authors having id = 1. Step 2: Include books that either have id = 1 or desc = 'abc'. |
I just tried with filter like this - https://localhost:7070/api/Authors/1?include=books&filter[books.desc]=eq:abc Giving me error like this
|
Why do you keep trying with legacy filter syntax? I already explained it does not work like that. Sounds like you need two filters:
That would be: If that's not what you need, please provide sample records for both tables and the expected response. |
@anand2122 Does this answer your question? Do you need this issue to remain open? |
SUMMARY
We are trying to filter with an included object using a legacy filter giving up errors
DETAILS
Hi,
We are trying to filter with an included object using a legacy filter (e.g., exp:), but we are not getting the expected results. We are receiving the following error:
"errors": [
{
"id": "e1112795-e822-4cab-8d94-b37075cb924d",
"status": "400",
"title": "The specified filter is invalid.",
"detail": "Field chain on resource type 'authors' failed to match the pattern: zero or more relationships, followed by a to-many relationship. Relationship on resource type 'books' expected. Failed at position 14: filter[books.^desc]",
"source": {
"parameter": "filter[books.desc]"
}
}
]
Also sometime getting this error as well
"detail": "This query string parameter can only be used on a collection of resources (not on a single resource)."
The normal filter works with the following URL:
https://localhost:7070/api/Authors?include=books&filter[books]=equals(desc,'pqr')
However, the legacy filter is causing issues:
https://localhost:7070/api/Authors?include=books&filter[books.desc]=expr:eq:1
`public class Book : Identifiable
{
[Key]
[Column("Id")]
public override int Id { get => base.Id; set => base.Id = value; }
[Attr(PublicName = "title")]
public string Title { get; set; }
}
public class Author : Identifiable
{
[Key]
[Column("Id")]
public override int Id { get => base.Id; set => base.Id = value; }
[Attr] public string Name { get; set; }
[HasMany] public List Books { get; set; }
}
`
API Response: I would need included filter response - "included":
{ "links": { "self": "https://localhost:7070/api/Authors?include=books", "first": "https://localhost:7070/api/Authors?include=books" }, "data": [ { "type": "authors", "id": "1", "attributes": { "name": "J.K. Rowling" }, "relationships": { "books": { "links": { "self": "https://localhost:7070/api/authors/1/relationships/books", "related": "https://localhost:7070/api/authors/1/books" }, "data": [ { "type": "books", "id": "1" }, { "type": "books", "id": "2" } ] } }, "links": { "self": "https://localhost:7070/api/authors/1" } }, { "type": "authors", "id": "2", "attributes": { "name": "George R.R. Martin" }, "relationships": { "books": { "links": { "self": "https://localhost:7070/api/authors/2/relationships/books", "related": "https://localhost:7070/api/authors/2/books" }, "data": [ { "type": "books", "id": "3" }, { "type": "books", "id": "4" } ] } }, "links": { "self": "https://localhost:7070/api/authors/2" } }, { "type": "authors", "id": "3", "attributes": { "name": "J.R.R. Tolkien" }, "relationships": { "books": { "links": { "self": "https://localhost:7070/api/authors/3/relationships/books", "related": "https://localhost:7070/api/authors/3/books" }, "data": [ { "type": "books", "id": "5" }, { "type": "books", "id": "6" } ] } }, "links": { "self": "https://localhost:7070/api/authors/3" } } ], "included": [ { "type": "books", "id": "1", "attributes": { "title": "Harry Potter and the Philosopher's Stone", "desc": "abc" }, "relationships": { "author": { "links": { "self": "https://localhost:7070/api/books/1/relationships/author", "related": "https://localhost:7070/api/books/1/author" } } }, "links": { "self": "https://localhost:7070/api/books/1" } }, { "type": "books", "id": "2", "attributes": { "title": "Harry Potter and the Chamber of Secrets", "desc": "pqr" }, "relationships": { "author": { "links": { "self": "https://localhost:7070/api/books/2/relationships/author", "related": "https://localhost:7070/api/books/2/author" } } }, "links": { "self": "https://localhost:7070/api/books/2" } }, { "type": "books", "id": "3", "attributes": { "title": "A Game of Thrones", "desc": "sss" }, "relationships": { "author": { "links": { "self": "https://localhost:7070/api/books/3/relationships/author", "related": "https://localhost:7070/api/books/3/author" } } }, "links": { "self": "https://localhost:7070/api/books/3" } }, { "type": "books", "id": "4", "attributes": { "title": "A Clash of Kings", "desc": "The notes" }, "relationships": { "author": { "links": { "self": "https://localhost:7070/api/books/4/relationships/author", "related": "https://localhost:7070/api/books/4/author" } } }, "links": { "self": "https://localhost:7070/api/books/4" } }, { "type": "books", "id": "5", "attributes": { "title": "The Hobbit", "desc": null }, "relationships": { "author": { "links": { "self": "https://localhost:7070/api/books/5/relationships/author", "related": "https://localhost:7070/api/books/5/author" } } }, "links": { "self": "https://localhost:7070/api/books/5" } }, { "type": "books", "id": "6", "attributes": { "title": "The Lord of the Rings", "desc": null }, "relationships": { "author": { "links": { "self": "https://localhost:7070/api/books/6/relationships/author", "related": "https://localhost:7070/api/books/6/author" } } }, "links": { "self": "https://localhost:7070/api/books/6" } } ] }
STEPS TO REPRODUCE
Postman request: https://localhost:7070/api/Authors?include=books&filter[books.desc]=expr:eq:1
VERSIONS USED
The text was updated successfully, but these errors were encountered: