Module: Immunio::RelationHooks
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/immunio/plugins/active_record_relation.rb
Instance Method Summary collapse
-
#clone_with_immunio ⇒ Object
ActiveRecord will “spawn”, or clone, relations under many circumstances.
Instance Method Details
#clone_with_immunio ⇒ Object
ActiveRecord will “spawn”, or clone, relations under many circumstances. For example, #where will first spawn the relation, then add the where clause to the new relation, then return the new relation. This is so you can do something like:
prods = Product.where(cost: 10)
# Return blue products costing $10 prods_blue = prods.where(color: ‘blue’).to_a
# Return count of all products costing $10 prods_count = prods.count
We must track the prods relation and the relations returned by the color where call separately.
23 24 25 26 27 28 29 30 31 |
# File 'lib/immunio/plugins/active_record_relation.rb', line 23 def clone_with_immunio cloned = clone_without_immunio Request.time "plugin", "Immunio::RelationTracking" do QueryTracker.instance.spawn_relation self, cloned end cloned end |