Skip to content
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

Updating mutiple fields in a Model by passing a reference #460

Closed
VaZark opened this issue Jan 16, 2022 · 3 comments · Fixed by #492
Closed

Updating mutiple fields in a Model by passing a reference #460

VaZark opened this issue Jan 16, 2022 · 3 comments · Fixed by #492
Assignees

Comments

@VaZark
Copy link

VaZark commented Jan 16, 2022

From what I've seen in the Basic CRUD section of the docs, it seems like we need to manually Set every field that needs to be updated before passing to the update function.

Is there any method to pass a reference and expect it to update all or most of the fields?

@billy1624
Copy link
Member

Hey @VaZark, I'm not sure what you mean by "pass a reference and expect it to update all or most of the fields". Could you show me a demo for it? Thanks!

@VaZark
Copy link
Author

VaZark commented Jan 20, 2022

    let task: Option<task::Model> = Task::find_by_id(id)
        .one(conn)
        .await
        .expect("Error fetching");

    // Parsed from input JSON<task::Model>
    let mut payload: task::ActiveModel = payload.into(); 
    payload.id = Set(task.id);

   // When I run the following, I expected it to update all the fields
   // However since only the id field is Set, only that is updated (makes sense ofc)
    let updated_task = payload.update(conn).await;  
    
   //It would cleaner if I could do something like
    let updated_task = payload.updateAllFields(conn).await;  

@billy1624
Copy link
Member

Related #346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants