0

I would like find audited changes of state but i dont know who find audited changes from any states

I try this and its work but i would like find last audited change from any states to offboarded:

product.audits.where("audited_changes LIKE '%state:%published%offboarded%'").last

I would like something like this: LIKE '%state:%ANY WORD%offboarded%'

audited change format:

audited_changes: {"state"=>["published", "offboarded"]}

I want find this result too for example:

audited_changes: {"state"=>["hidden", "offboarded"]}

I use Rails with postgresql

Wako
  • 140
  • 1
  • 15

1 Answers1

1

I think you can use the @> operator ("contains" operator) in your where clause:

product.audits.where("audited_changes @> '{\"state\": [\"published\", \"offboarded\"]}'")

Docs for different data types:

markets
  • 6,709
  • 1
  • 38
  • 48