roy-ganz / toql

A friendly and productive ORM
50 stars 1 forks source link

Allow embedded structs (and keys) #2

Open roy-ganz opened 3 years ago

roy-ganz commented 3 years ago

This is currently not possible, because embedded structs are not supported

#[derive(Toql)]
struct User {
  #[toql(key)]
  pub id: u64,
  pub modified_by: UserKey // <-- UserKey{ id: u64}
}

An embedded UserKey would map the modified_by column from User to the id field of UserKey.

Note that this actually compiles, but fails with a runtime error (expected field XX to be selected).

Workaround: Use u64 directly or join on a additional struct (eg. UserRef).

To implement embedding decide on column renaming, composite keys and general structs handling.