Created
July 1, 2017 17:49
-
-
Save YetAnotherMinion/2a472a1b010bc2c5366bc0acd0744cb0 to your computer and use it in GitHub Desktop.
single column foreign key with diesel 0.13.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate diesel; | |
#[macro_use] | |
extern crate diesel_codegen; | |
table! { | |
// table_a (tennant_id, part_number) { | |
table_a (tennant_id) { | |
tennant_id -> Int8, | |
part_number -> Int8, | |
} | |
} | |
table! { | |
table_b (id) { | |
id -> Int8, | |
foo_tennant_id -> Int8, | |
foo_part_number -> Int8, | |
order_quantity -> Int8, | |
} | |
} | |
#[derive(Queryable, Insertable, Identifiable, Associations)] | |
#[table_name = "table_a"] | |
#[has_many(table_b, foreign_key = "foo_tennant_id")] | |
#[primary_key(tennant_id, part_number)] | |
pub struct TableA { | |
pub tennant_id : i64, | |
pub part_number : i64, | |
} | |
#[derive(Queryable, Insertable, Identifiable, Associations)] | |
#[table_name = "table_b"] | |
#[belongs_to(TableA)] | |
#[primary_key(id)] | |
pub struct TableB { | |
pub id : i64, | |
pub foo_tennant_id : i64, | |
pub foo_part_number : i64, | |
pub order_quantity : i64, | |
} | |
fn main() { | |
println!("Hello, world!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment