Plume/plume-models/src/post_authors.rs

24 lines
567 B
Rust
Raw Normal View History

2020-01-21 06:02:03 +00:00
use crate::{posts::Post, schema::post_authors, users::User, Error, Result};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
2018-04-24 09:21:39 +00:00
2018-09-27 21:06:40 +00:00
#[derive(Clone, Queryable, Identifiable, Associations)]
2018-04-29 20:23:44 +00:00
#[belongs_to(Post)]
#[belongs_to(User, foreign_key = "author_id")]
2018-04-23 14:37:49 +00:00
pub struct PostAuthor {
pub id: i32,
pub post_id: i32,
pub author_id: i32,
2018-04-23 14:37:49 +00:00
}
#[derive(Insertable)]
#[table_name = "post_authors"]
pub struct NewPostAuthor {
pub post_id: i32,
pub author_id: i32,
2018-04-23 14:37:49 +00:00
}
impl PostAuthor {
insert!(post_authors, NewPostAuthor);
get!(post_authors);
2018-04-23 14:37:49 +00:00
}