I am trying to create a list query that filters its rows by a value on the last created child (one to many relation). To put an example, imagine a books and categories entity with a historical changes on those categories as well.
Books
id | name
1 | book1
2 | book2
3 | book3
Categories
id | name
1 | category1
2 | category2
3 | category3
BookCategoryHistory
book_id | category_id | created_at …
1 | 1 | 01-02-2020
1 | 3 | 02-04-2020
2 | 1 | 03-02-2020
…
Given those tables, imagine that i would like to find the books that has as the latest category the category3, how could i do that ? Maybe i am struggling too much with this an there is an easy solution, but right now i find myself unable to do it.