mirror of
https://github.com/Phundrak/georm.git
synced 2025-12-13 16:31:51 +01:00
test: added tests for M2M relationships, it works
This commit is contained in:
@@ -35,7 +35,13 @@ impl Ord for Author {
|
||||
table = "books",
|
||||
one_to_many = [
|
||||
{ name = "reviews", remote_id = "book_id", table = "reviews", entity = Review }
|
||||
]
|
||||
],
|
||||
many_to_many = [{
|
||||
name = "genres",
|
||||
table = "genres",
|
||||
entity = Genre,
|
||||
link = { table = "book_genres", from = "book_id", to = "genre_id" }
|
||||
}]
|
||||
)]
|
||||
pub struct Book {
|
||||
#[georm(id)]
|
||||
@@ -66,3 +72,20 @@ pub struct Review {
|
||||
pub book_id: i32,
|
||||
pub review: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, sqlx::FromRow, Georm, PartialEq, Eq)]
|
||||
#[georm(
|
||||
table = "genres",
|
||||
many_to_many = [{
|
||||
name = "books",
|
||||
table = "books",
|
||||
entity = Book,
|
||||
remote_id = "ident",
|
||||
link = { table = "book_genres", from = "genre_id", to = "book_id" }
|
||||
}]
|
||||
)]
|
||||
pub struct Genre {
|
||||
#[georm(id)]
|
||||
id: i32,
|
||||
name: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user