test: one-to-many relationships work

This commit is contained in:
Lucien Cartier-Tilet 2025-01-31 22:22:06 +01:00
parent bca0619f30
commit 86e29fa2dc
Signed by: phundrak
GPG Key ID: 347803E8073EACE0
2 changed files with 8 additions and 2 deletions

View File

@ -7,4 +7,5 @@ VALUES ('The Lord of the Rings: The Fellowship of the Ring', 1),
INSERT INTO reviews (book_id, review)
VALUES (1, 'Great book'),
(3, 'Awesome book'),
(2, 'Probably his best work!'),
(2, 'Greatest book');

View File

@ -31,7 +31,12 @@ impl Ord for Author {
}
#[derive(Debug, sqlx::FromRow, Georm, PartialEq, Eq, Default)]
#[georm(table = "books")]
#[georm(
table = "books",
one_to_many = [
{ name = "reviews", remote_id = "book_id", table = "reviews", entity = Review }
]
)]
pub struct Book {
#[georm(id)]
ident: i32,
@ -59,5 +64,5 @@ pub struct Review {
pub id: i32,
#[georm(relation = {entity = Book, table = "books", remote_id = "ident", name = "book"})]
pub book_id: i32,
pub review: String
pub review: String,
}