aboutsummaryrefslogtreecommitdiff
path: root/examples/tutorial02/polls/models.rs
blob: cd480dae3d9b901302d5de7e43be172f245d0667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use tosin::db::models::{gather, Id, Model};

#[derive(Model, PartialEq, Debug)]
pub struct Question {
    id: Option<Id>,
    #[model(max_length = 200)]
    question_text: String,
    /// date published
    pub_date: chrono::NaiveDateTime,
}

#[derive(Model, PartialEq, Debug)]
pub struct Choice {
    id: Option<Id>,
    #[model(Question, on_delete=Cascade)]
    question: Id,
    #[model(max_length = 200)]
    choice_text: String,
    #[model(default = 0)]
    votes: i64,
}

gather!();