rewhere

rewhere(conditions)
Instance Public methods

Allows you to change a previously set where condition for a given attribute, instead of appending to that condition.

Post.where(trashed: true).where(trashed: false)                       # => WHERE `trashed` = 1 AND `trashed` = 0
Post.where(trashed: true).rewhere(trashed: false)                     # => WHERE `trashed` = 0
Post.where(active: true).where(trashed: true).rewhere(trashed: false) # => WHERE `active` = 1 AND `trashed` = 0

This is short-hand for unscope(where: conditions.keys).where(conditions). Note that unlike reorder, we're only unscoping the named conditions รข not the entire where statement.

doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.