refactor(db): Establish Post->Thread association

This makes it possible to query posts by thread via Diesel.
This commit is contained in:
Vincent Ambo 2018-04-08 18:27:15 +02:00
parent 6e56f8e729
commit 316036b0a8
5 changed files with 15 additions and 7 deletions

View file

@ -47,11 +47,15 @@ impl Handler<GetThread> for DbExecutor {
fn handle(&mut self, msg: GetThread, _: &mut Self::Context) -> Self::Result {
use schema::threads::dsl::*;
let conn = self.0.get().unwrap();
let result: Thread = threads
let thread_result: Thread = threads
.find(msg.0).first(&conn)
.expect("Error loading thread");
Ok((result, vec![]))
let post_list = Post::belonging_to(&thread_result)
.load::<Post>(&conn).expect("Error loading posts for thread");
Ok((thread_result, post_list))
}
}