kurtbuilds / ormlite

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

derive Clone for Join #45

Closed nitn3lav closed 2 months ago

nitn3lav commented 9 months ago

Please note that this will break code like this because calls to clone and to_owned will no longer be dereferenced:

#[derive(Debug, Model)]
struct A {
    id: Uuid,
    #[ormlite(join_column = "b")]
    b: Join<B>
}

#[derive(Clone, Debug, Model)]
struct B {
    id: Uuid,
}

fn hi(a: A) {
    // no longer works
    let x: B = a.b.to_owned();
    // now works
    let y: Join<B> = a.b.to_owned();
    // still works
    let z: B = (*a.b).to_owned();
}
kurtbuilds commented 9 months ago

Can you provide a rationale and example code for why you'd want to Clone a Join struct? My mental model is that it's owned by the queried object, and never lives elsewhere. Definitely happy to include it if it makes sense, just concerned it might also lead to mistakes where users think they're updating the values, but it was only the clone that was updated.