test: added tests for M2M relationships, it works

This commit is contained in:
2025-01-31 22:52:28 +01:00
parent 86e29fa2dc
commit b70b4b7a81
5 changed files with 93 additions and 5 deletions

View File

@@ -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,
}