2018-11-24 12:44:17 +01:00
|
|
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
2018-04-24 11:21:39 +02:00
|
|
|
|
2018-06-23 18:36:11 +02:00
|
|
|
use posts::Post;
|
2018-04-23 16:37:49 +02:00
|
|
|
use schema::post_authors;
|
2018-11-24 12:44:17 +01:00
|
|
|
use users::User;
|
2018-04-23 16:37:49 +02:00
|
|
|
|
2018-09-27 23:06:40 +02:00
|
|
|
#[derive(Clone, Queryable, Identifiable, Associations)]
|
2018-04-29 22:23:44 +02:00
|
|
|
#[belongs_to(Post)]
|
|
|
|
#[belongs_to(User, foreign_key = "author_id")]
|
2018-04-23 16:37:49 +02:00
|
|
|
pub struct PostAuthor {
|
|
|
|
pub id: i32,
|
|
|
|
pub post_id: i32,
|
2018-11-24 12:44:17 +01:00
|
|
|
pub author_id: i32,
|
2018-04-23 16:37:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Insertable)]
|
|
|
|
#[table_name = "post_authors"]
|
|
|
|
pub struct NewPostAuthor {
|
|
|
|
pub post_id: i32,
|
2018-11-24 12:44:17 +01:00
|
|
|
pub author_id: i32,
|
2018-04-23 16:37:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PostAuthor {
|
2018-06-18 15:57:38 +02:00
|
|
|
insert!(post_authors, NewPostAuthor);
|
2018-06-18 15:44:23 +02:00
|
|
|
get!(post_authors);
|
2018-04-23 16:37:49 +02:00
|
|
|
}
|