@silencebringer,
When he gives:
return $this->hasOne(Post::class, 'thread_id', 'ID')->latestOfMany();
Did not work.
When I change to:
return $this->hasOne(Post::class, 'thread_id', 'id')->latestOfMany();
It works, but it does not search for my recently written post by searching threads in a given category.
When I present in the Category model:
return $this->hasOne(Post::class)->latestOfMany();
Receives a message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'posts.category_id' in 'field list' (SQL: select `posts`.* from `posts` inner join (select MAX(`posts`.`id`) as `id_aggregate`, `posts`.`category_id` from `posts` where `posts`.`category_id` in (1, 2) group by `posts`.`category_id`) as `latestOfMany` on `latestOfMany`.`id_aggregate` = `posts`.`id` and `latestOfMany`.`category_id` = `posts`.`category_id`)
May you understand what he wants to delay.
I have 3 models:
- category - id,
- thread - id, categories_id
- post - id, thread_id
In the category - he wants to take out the last post that was written and connect it with a relationship with the thread.