kurtbuilds / ormlite

An ORM in Rust for developers that love SQL.
https://crates.io/crates/ormlite
MIT License
234 stars 13 forks source link

id field is needed in separate insertion struct #53

Closed SpartanPlume closed 2 months ago

SpartanPlume commented 2 months ago

When using a separate insertion struct, the id field is mandatory while it should not.

Dependencies:

[dependencies]
ormlite = { version = "0.18", features = ["postgres"] }

Reproducer:

use ormlite::model::*;

#[derive(Model, Debug)]
pub struct Person {
    pub id: i32,
    pub name: String,
}

#[derive(Model, Debug)]
#[ormlite(table = "person")]
pub struct InsertPerson {
    pub name: String,
}

Errors:

error: proc-macro derive panicked
 --> src/main.rs:3:10
  |
3 | #[derive(Model, Debug)]
  |          ^^^^^
  |
  = help: message: No column marked with #[ormlite(primary_key)], and no column named id, uuid, person_id, or person_uuid

error: proc-macro derive panicked
 --> src/main.rs:9:10
  |
9 | #[derive(Model, Debug)]
  |          ^^^^^
  |
  = help: message: No column marked with #[ormlite(primary_key)], and no column named id, uuid, person_id, or person_uuid

As you can see, the error is appearing on both the insertion struct and the original one.

If the id field is added, the errors disappear.

kurtbuilds commented 2 months ago

See #54