about summary refs log tree commit diff
path: root/src/db.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-08T16·27+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-08T16·30+0200
commit316036b0a89a428e850ea33e07f5fe2362f833c9 (patch)
tree489a4e6c8b7e8f117b054d0087981027f288aad3 /src/db.rs
parent6e56f8e729551ff14b7a72ca889b8dd38999fb2d (diff)
refactor(db): Establish Post->Thread association
This makes it possible to query posts by thread via Diesel.
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/db.rs b/src/db.rs
index c3a05a32372b..1aa6ff73c78c 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -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))
     }
 }