2018-04-24 09:21:39 +00:00
|
|
|
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
|
|
|
|
2018-06-23 16:36:11 +00:00
|
|
|
use posts::Post;
|
|
|
|
use users::User;
|
2018-04-23 14:37:49 +00:00
|
|
|
use schema::post_authors;
|
|
|
|
|
2018-04-29 20:23:44 +00:00
|
|
|
#[derive(Queryable, Identifiable, Associations)]
|
|
|
|
#[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
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Insertable)]
|
|
|
|
#[table_name = "post_authors"]
|
|
|
|
pub struct NewPostAuthor {
|
|
|
|
pub post_id: i32,
|
|
|
|
pub author_id: i32
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PostAuthor {
|
2018-06-18 13:57:38 +00:00
|
|
|
insert!(post_authors, NewPostAuthor);
|
2018-06-18 13:44:23 +00:00
|
|
|
get!(post_authors);
|
2018-04-23 14:37:49 +00:00
|
|
|
}
|