Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upError using Identifiable struct with only id field #1013
Comments
agersant
changed the title from
Error using Identifiable struct with only one field
to
Error using Identifiable struct with only id field
Jul 10, 2017
This comment has been minimized.
|
If you User struct only has the id field, do you even need the |
This comment has been minimized.
agersant
commented
Jul 12, 2017
•
|
Sorry if I didn't explain this right. There are two The second |
This comment has been minimized.
|
@agersant I think you're just running into a quirky (but intentional) edge case. |
This comment has been minimized.
agersant
commented
Jul 12, 2017
|
Oh that makes sense. I had not realized that without the trailing comma, the select argument was a lone value and not a 1-item tuple (even with the extra parenthesis around the field name). Sorry for the false bug report Everything does work as expected without a select call. |
agersant commentedJul 10, 2017
Setup
Versions
Feature Flags
Problem Description
When gathering key values for a join via
belonging_to, it is not possible to store the keys in a struct which holdsidand no other fields.What are you trying to accomplish?
I run a setup very similar to the posts and users example from the docs so I'll use it for illustration.
The following code works fine (it's from the docs):
Now let's imagine the
Usertable and its corresponding struct have many more columns. We would like to only select theidcolumn from the users table (either for performance or to avoid exposing a full fledgedUserstruct to a module that doesn't need it).We can define a local User struct that only has a
idfield and update our user query accordingly:The query returns the actual id and not a struct containing the id so we get this error:
the traitdiesel::types::FromSqlRow<diesel::types::Integer, diesel::sqlite::Sqlite>is not implemented for(i32,)``.This seems reasonable so let's change our code to:
We now receive the following error:
the traitdiesel::BelongingToDslis not implemented forPost``. Also fairly reasonable, so let's update ourbelongs_tostatement on `Post` accordingly:We now receive:
conflicting implementations of traitdiesel::JoinTo<_>for typedb::schema::__diesel_infer_schema::infer_posts::posts::table:I don't know where to go from here.
Workaround
The only workaround I found is to define a second field on the local
Userstruct and change the user query to.select((id, other_field)). This actually lets everything compile but the Rust compiler correctly emits a warning that other_field is never used and could/should be removed.Checklist