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

Touch method on model and on associations #486

Open
koenpunt opened this issue Jan 22, 2015 · 0 comments
Open

Touch method on model and on associations #486

koenpunt opened this issue Jan 22, 2015 · 0 comments
Labels

Comments

@koenpunt
Copy link
Collaborator

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 koenpunt changed the title Touch method on model and on associations Feature: Touch method on model and on associations Jan 22, 2015
@koenpunt koenpunt changed the title Feature: Touch method on model and on associations Touch method on model and on associations Jan 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant