mirror of
				https://github.com/Phundrak/georm.git
				synced 2025-11-04 01:11:10 +00:00 
			
		
		
		
	test: one-to-many relationships work
This commit is contained in:
		
							parent
							
								
									bca0619f30
								
							
						
					
					
						commit
						86e29fa2dc
					
				
							
								
								
									
										1
									
								
								tests/fixtures/o2o.sql
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								tests/fixtures/o2o.sql
									
									
									
									
										vendored
									
									
								
							@ -7,4 +7,5 @@ VALUES ('The Lord of the Rings: The Fellowship of the Ring', 1),
 | 
				
			|||||||
INSERT INTO reviews (book_id, review)
 | 
					INSERT INTO reviews (book_id, review)
 | 
				
			||||||
VALUES (1, 'Great book'),
 | 
					VALUES (1, 'Great book'),
 | 
				
			||||||
       (3, 'Awesome book'),
 | 
					       (3, 'Awesome book'),
 | 
				
			||||||
 | 
					       (2, 'Probably his best work!'),
 | 
				
			||||||
       (2, 'Greatest book');
 | 
					       (2, 'Greatest book');
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,12 @@ impl Ord for Author {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, sqlx::FromRow, Georm, PartialEq, Eq, Default)]
 | 
					#[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 {
 | 
					pub struct Book {
 | 
				
			||||||
    #[georm(id)]
 | 
					    #[georm(id)]
 | 
				
			||||||
    ident: i32,
 | 
					    ident: i32,
 | 
				
			||||||
@ -59,5 +64,5 @@ pub struct Review {
 | 
				
			|||||||
    pub id: i32,
 | 
					    pub id: i32,
 | 
				
			||||||
    #[georm(relation = {entity = Book, table = "books", remote_id = "ident", name = "book"})]
 | 
					    #[georm(relation = {entity = Book, table = "books", remote_id = "ident", name = "book"})]
 | 
				
			||||||
    pub book_id: i32,
 | 
					    pub book_id: i32,
 | 
				
			||||||
    pub review: String
 | 
					    pub review: String,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user