How can I update only a particular set of fields to the database with Play? Currently I have a User model that contains a specific field, let call it: isAdministrator:
private boolean isAdministrator;
And I have the accessor methods:
/**
* @return the isAdministrator
*/
public boolean isAdministrator() {
return isAdministrator;
}
/**
* @param isAdministrator
* the isAdministrator to set
*/
public void setAdministrator(boolean isAdministrator) {
this.isAdministrator = isAdministrator;
}
But when I change the username, via a form where isAdministrator is NOT included, Play resets my User objects and sets the value 0 for this user?
So, how can I update only the changed fields?
I don’t directly answer to your question, but instead of having a boolean indicating that your User is an admin or not, I would create an
Adminclass which inherits from the User.It’s the “S” of SOLID 😉
EDIT:
In the controller, you can load the old value from the database before updating with the form values: