Saves all changes into the Model ( including relationships )
@return Boolean
Params
EMPTY
Explanation
Simple like that. It will save all changes ( if are a opened registry ) or will create a new entry into your database.
Creating a new record
$user = new Users();
$user->fist_name = "Klederson";
$user->last_name = "Bueno";
$user->birthday = "1986-05-17";
$user->gender = "male";
if( $user->save() ) {
print "Saved!";
} else {
print "Something goes very wrong! Bad bad server";
}
Creating a new record
$user = new Users();
$user->get(1);
$user->birthday = "1986-05-17";
$user->gender = "male";
if( $user->save() ) {
print "Saved!";
} else {
print "Something goes very wrong! Bad bad server";
}
The above example will UPDATE only the birthday and gender columns because it regonizes its a existent record and only those two fields had been changed.
Creating a new record with relationship
*Assuming we have a albums relationship mapped
$user = new Users();
$user->fist_name = "Klederson";
$user->last_name = "Bueno";
$user->birthday = "1986-05-17";
$user->gender = "male";
$user->albums = new Albums();
$user->albums->name = "My Travel";
if( $user->save() ) {
print "Saved!";
} else {
print "Something goes very wrong! Bad bad server";
}
It will perform TWO inserts one into the users table and other into the albums table creating the relationship with the new created user.
Once again… BE CREATIVE
