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

@ -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>,
}