Updating objects with Gideon
Gideon can update a single object or a group objects depending on how it is invoked, please make sure you read and understand the documentation as missues of this method can cause data corruption
update( %changes )
as a Class method
When update
is invoked for a Gideon class it updates all records in a data store with %changes
.
# Update all objects in the data store
People->update( status => 'active' );
update( %changes )
as an Instance method
When update
is invoked for a Gideon class instance it updates that particular record and not the rest of the records
# Update one object
People->find_one( id => 1 )->update( id => 2 );
Updating object with save
Additionally you can use the save
method to update a particular object.
my $person = People->find_one( id => 1 );
# Update only the name
$person->update( name => 'John Doe' );
# Query: UPDATE ... SET name = 'John Doe' WHERE id = 1
# Update names
$person->name('John Doe');
$person->save;
# Query: UPDATE ... SET id = 1, name = 'John Doe', ... WHERE id = 1
The difference between save
and update
is that update
gives you a fine grained control on which fields to update. save
sends the entire record as a whole to the data store.