NyxCode / ormx

bringing orm-like features to sqlx
MIT License
287 stars 32 forks source link

Example for PgSql with relationships #16

Closed Milo123459 closed 2 years ago

NyxCode commented 2 years ago

ormx does not directly support relations like a real ORM would. Your structs must directly mirror the database table.
If, for example, you got Author and Book, and you want to get all books written by one author, you'd do something like

#[derive(ormx::Table)]
#[ormx(table = "books", id = book_id)]
struct Book {
  book_id: i32,
  #[ormx(get_many = by_author(i32)]
  author_id: i32
}

let author = ...;
let books = Book::by_author(author.author_id).await?;