Skip to content

Commit

Permalink
Replace raw string where clause with query methods
Browse files Browse the repository at this point in the history
Should effectively be the same query but easier to read and with the benefit of ActiveRecord's type casting and association reflection. Fixes issue dealing with mutiple id column types
  • Loading branch information
macowie authored and danielmorrison committed Dec 23, 2022
1 parent 7212260 commit c5fdb37
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ def audited_attributes

# Returns a list combined of record audits and associated audits.
def own_and_associated_audits
Audited.audit_class.unscoped
.where("(auditable_type = :type AND auditable_id = :id) OR (associated_type = :type AND associated_id = :id)",
type: self.class.base_class.name, id: id)
Audited.audit_class.unscoped.where(auditable: self)
.or(Audited.audit_class.unscoped.where(associated: self))
.order(created_at: :desc)
end

Expand Down

0 comments on commit c5fdb37

Please sign in to comment.