Ruby: Model ActiveRecord::Relation#touch_all

This commit is contained in:
Harry Maclean
2022-06-17 10:19:53 +12:00
parent 7dfab371f6
commit 20ff4c4299
3 changed files with 28 additions and 1 deletions

View File

@@ -359,7 +359,7 @@ private module Persistence {
}
/**
* Holds if `call` has a keyword argument of with value `value`.
* Holds if `call` has a keyword argument with value `value`.
*/
private predicate keywordArgumentWithValue(DataFlow::CallNode call, DataFlow::ExprNode value) {
exists(ExprNodes::PairCfgNode pair | pair = call.getArgument(_).asExpr() |
@@ -412,6 +412,28 @@ private module Persistence {
}
}
/**
* A call to `ActiveRecord::Relation#touch_all`, which updates the `updated_at`
* attribute on all records in the relation, setting it to the current time or
* the time specified. If passed additional attribute names, they will also be
* updated with the time.
* Examples:
* ```rb
* Person.all.touch_all
* Person.where(name: "David").touch_all
* Person.all.touch_all(:created_at)
* Person.all.touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
* ```
*/
private class TouchAllCall extends DataFlow::CallNode, PersistentWriteAccess::Range {
TouchAllCall() {
exists(this.asExpr().getExpr().(ActiveRecordModelClassMethodCall).getReceiverClass()) and
this.getMethodName() = "touch_all"
}
override DataFlow::Node getValue() { result = this.getKeywordArgument("time") }
}
/** A call to e.g. `User.insert_all([{name: "foo"}, {name: "bar"}])` */
private class InsertAllLikeCall extends DataFlow::CallNode, PersistentWriteAccess::Range {
private ExprNodes::ArrayLiteralCfgNode arr;