about summary refs log tree commit diff
path: root/src/models.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/models.rs
parent6e56f8e729551ff14b7a72ca889b8dd38999fb2d (diff)
refactor(db): Establish Post->Thread association
This makes it possible to query posts by thread via Diesel.
Diffstat (limited to 'src/models.rs')
-rw-r--r--src/models.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/models.rs b/src/models.rs
index 74b386a19cf9..42d8d11649ff 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -1,6 +1,7 @@
 use chrono::prelude::{DateTime, Utc};
+use schema::{threads, posts};
 
-#[derive(Queryable, Serialize)]
+#[derive(Identifiable, Queryable, Serialize)]
 pub struct Thread {
     pub id: i32,
     pub title: String,
@@ -8,10 +9,11 @@ pub struct Thread {
     pub posted: DateTime<Utc>,
 }
 
-#[derive(Queryable, Serialize)]
+#[derive(Identifiable, Queryable, Serialize, Associations)]
+#[belongs_to(Thread)]
 pub struct Post {
     pub id: i32,
-    pub thread: i32,
+    pub thread_id: i32,
     pub body: String,
     pub posted: DateTime<Utc>,
 }