New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[changeset_for] codegen issue #50

Closed
mcasper opened this Issue Dec 4, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@mcasper
Collaborator

mcasper commented Dec 4, 2015

Trying to use #[changeset_for] for the struct:

#[changeset_for(users)]
pub struct UserChanges {
    id: i32,
    first_name: Option<String>,
    last_name: Option<String>,
    email: Option<String>,
}

Produces the error:

src/main.rs:33:24: 33:24 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::VarChar, diesel::types::VarChar)>` is not implemented for the type `UserChanges` [E0277]
src/main.rs:33 #[changeset_for(users)]
                                      ^
src/main.rs:33:1: 33:24 note: in this expansion of try! (defined in <std macros>)
src/main.rs:33:24: 33:24 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to previous error

However, adding #[derive(Queriable)] to the struct annotation raises the error:

src/main.rs:34:24: 34:24 error: the trait `diesel::types::FromSqlRow<(diesel::types::Integer, diesel::types::VarChar, diesel::types::VarChar, diesel::types::VarChar)>` is not implemented for the type `(i32, core::option::Option<collections::string::String>, core::option::Option<collections::string::String>, core::option::Option<collections::string::String>)` [E0277]
src/main.rs:34 #[changeset_for(users)]
                                      ^
src/main.rs:34:1: 34:24 note: in this expansion of try! (defined in <std macros>)
src/main.rs:34:24: 34:24 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to previous error

Halp

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 4, 2015

You'll need to use two different structs for that use case. (Which makes sense if you think about it, you don't want to have to deal with options for reads, when you know the field is always present)

@sgrif sgrif closed this Dec 4, 2015

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 4, 2015

(I might eventually be able to support reading a non-nullable field into an option, but at the moment coherence prevents it)

@mcasper

This comment has been minimized.

Collaborator

mcasper commented Dec 4, 2015

I'm totally fine to (and prefer to) use separate structs for changesets and queriable, but the first error comes from just using #[changeset_for(users)] on the UserChanges struct

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 4, 2015

Oh, whoops!

@sgrif sgrif reopened this Dec 4, 2015

@sgrif sgrif closed this in fbf12e7 Dec 4, 2015

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 4, 2015

^----- That commit probably also makes save_changes way more useful for your use case as well

@mcasper

This comment has been minimized.

Collaborator

mcasper commented Dec 4, 2015

Definitely, that's awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment