Let's say I have three models in Loopback: Reader, Book and Note. Reader is an instance of User and can log in. Relations are like that:
- Reader has many Books
- Reader has many Notes
- Book has many Notes
- Note belongs to Reader
- Note belongs to Book
What I am trying to achieve is to query all Books of a logged-in Reader with populated Notes that belong to the Book and the Reader.
Api call would look like that:
/api/reader/me/books?filter[include]=notes
But this returns all the notes belonging to the Book regardless if they belong to the Reader. I could add another filter to the api call but I need to filter the Notes on server side so that the reader does not have access to other readers' notes.
I've tried to add this access control to Book model:
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__get__notes"
}
and this acl to Note model
[
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
}, {
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "*"
}
]
It works well for calls like this
/api/reader/me/books/<bookId>/notes
but not for the first call with include filter. What should I do to get just reader's notes populated in the books?
Any help much appreciated.