I have the following use caseBooks
and a collection called Authors
which are connected to each other by reference. I then have an AfterGet hook for the Books collection like so:
export function Books_afterGet(item, context) {
let chaptersCount = item.pageCount / 30;
item.chapters = chaptersCount;
return item
}
Now this works fine when I get a book like so:
let book = await wixData.get('Books', someID);
console.log(book.chapters)
but when I fetch it by author reference like this:
let author = await wixData.query('Authors').eq('_id', authorId).include('books').find();
console.log(author.books[0].chapters);
then I get undefined, meaning that the afterGet hook did not run as I would expect it to.
Why is this working like that? How can I query with include and have the afterGet hook running on these objects?