php-activerecord icon indicating copy to clipboard operation
php-activerecord copied to clipboard

Touch method on model and on associations

Open koenpunt opened this issue 10 years ago • 0 comments

Just like Rails' AR method touch

$user = User::find(1);
$user->update_attributes(['name' => 'Foo Bar']); //=> updates `updated_at` by calling `touch` internally
$user->touch(); //=> updates `updated_at` field to current time
$user->touch('deleted_at'); //=> updates `deleted_at` and `updated_at` field to current time

And on associations, to update dependent models:

class User extends ActiveRecord\Model {
}

class Address extends ActiveRecord\Model {
  static $belongs_to = [
    ['user', 'touch' => true]
  ];
}

$address = Address::find_by_user_id(1);
$address->update_attributes(['zipcode' => '12345']); //=> updates `updated_at`, also for the User


koenpunt avatar Jan 22 '15 17:01 koenpunt