Replace deprecated ActiveRecord query