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 upAllow to ignore field os struct #860
Comments
killercup
added
the
enhancement
label
Apr 17, 2017
This comment has been minimized.
|
I'd call it |
This comment has been minimized.
DavidBM
commented
Apr 17, 2017
|
Umm, I don't know if I explain correctly the idea, maybe the serde annotation in my code confuses more than helps. What I was searching is a way to totally ignore that field in the database. That means, Diesel to load (in that case) always None in the Other question than can help. Having this struct: #[derive(Clone, Debug, Queryable, Serialize, AsChangeset, Identifiable, Associations)]
#[has_many(authors)]
pub struct User {
pub id: i32,
pub email: String,
pub author: Vec<Author>
}is possible to have something like |
This comment has been minimized.
Oh, yes, I think that's what I understood as well. I was suggesting
Did I get that right?
Currently, it's possible to get |
This comment has been minimized.
DavidBM
commented
Apr 17, 2017
|
Ok, you understand correctly :) Thanks! I will check this frequently! |
This comment has been minimized.
|
I've definitely warmed to the idea of marking a field as ignorable for update/insert (to skip a field for update, you can always use my hilarious, hacky workaround for now. I'm not sure I see the use case for skipping something on |
This comment has been minimized.
matt4682
commented
May 16, 2017
|
I think the only real use case for skipping a field on Using the example code from the association docs: let user = try!(users::find(1).first(&connection));
let posts = Post::belonging_to(&user).load(&connection);then you would make posts a proper child of user: user.posts = posts;The docs say that you could pass it around as {
"id": 0,
"name": "Foo",
"posts": []
}But passing it around as a tuple would have it represented as: {
"user": {
"id": 0,
"name": "Foo"
},
"posts": []
} |
Eijebong
referenced this issue
May 21, 2017
Closed
Request: macros for making `NewPost` and `Post` structs less redundant #919
This comment has been minimized.
TatriX
commented
Jan 20, 2018
|
My use case. I have a struct: #[derive(Deserialize, AsChangeset)]
#[table_name = "users"]
pub struct UpdateUserData {
username: Option<String>,
email: Option<String>,
bio: Option<String>,
image: Option<String>,
#[skip_somehow_plz]
password: Option<String>,
}I use this struct to parse POST params and then I'd like to use it as a changeset. So I want to skip |
This comment has been minimized.
|
I have the same use case as @TatriX, the reason I want the field to be in the same struct as |
This comment has been minimized.
TatriX
commented
Jan 29, 2018
|
As far as I know this depends on #1512 #[derive(Queryable)]
struct Foo {
id: i32,
name: String,
bar: Bar,
}
#[derive(Queryable)]
struct Bar {
id: i32,
name: String
}
let r: Vec<Foo> = foo::table.inner_join(bar::table).select((foo::id, foo::name, (bar::id, bar::name)).load(conn)?;I'm ready to take this issue if you think this should be implemented. |
This comment has been minimized.
|
It's not blocked on that PR. It just hasn't been a priority. As I mentioned in #860 (comment) though, if/when this lands, it'll be for |
This comment has been minimized.
TatriX
commented
Jan 30, 2018
•
|
It has a good use case to be implemented on |
DavidBM commentedApr 15, 2017
•
edited
Actually I have this struct
The column
authoris not in the database, but when I return the model, I would like to put inside of the struct theAuthor(a user can or not to have an author). For that I want to tell diesel that ignores the fieldauthor. I'm searching if something like#[ignore_field].