From 86e29fa2dcb7985ab3415a7288549cacb8be8f98 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Fri, 31 Jan 2025 22:22:06 +0100 Subject: [PATCH] test: one-to-many relationships work --- tests/fixtures/o2o.sql | 1 + tests/models.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/o2o.sql b/tests/fixtures/o2o.sql index 9ac8534..7b43179 100644 --- a/tests/fixtures/o2o.sql +++ b/tests/fixtures/o2o.sql @@ -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'); diff --git a/tests/models.rs b/tests/models.rs index bef3224..ad45b07 100644 --- a/tests/models.rs +++ b/tests/models.rs @@ -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, }