File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1270,6 +1270,33 @@ public function set_timestamps()
12701270 $ this ->created_at = $ now ;
12711271 }
12721272
1273+ /**
1274+ * Touch a model, updates `updated_at` and any other column given as argument.
1275+ *
1276+ * Please note that no validation is performed and only the after_touch, after_commit and after_rollback callbacks are executed.
1277+ *
1278+ * @param string|array $keys...
1279+ * @return bool True if update succeeds
1280+ * @throws ActiveRecord\ActiveRecordException if object is a new record
1281+ */
1282+ public function touch ($ keys = array () /*[, $key...] */ ){
1283+ if ($ this ->is_new_record ()){
1284+ throw new ActiveRecordException ('Cannot touch on a new record object ' );
1285+ }
1286+
1287+ if (!is_array ($ keys ))
1288+ $ keys = func_get_args ();
1289+
1290+ if (!in_array ('updated_at ' , $ keys ))
1291+ $ keys [] = 'updated_at ' ;
1292+
1293+ $ now = date ('Y-m-d H:i:s ' );
1294+ $ attributes = array_fill_keys ($ keys , $ now );
1295+
1296+ $ this ->set_attributes ($ attributes );
1297+ return $ this ->update (false );
1298+ }
1299+
12731300 /**
12741301 * Mass update the model with attribute data and saves to the database.
12751302 *
You can’t perform that action at this time.
0 commit comments