Where with a comparison operator in Rails 6.1




Rails 6
>> Post.where("DATE(published_at) > DATE(?)", Date.today)
# => <ActiveRecord::Relation [...]>

>> Post.find_by("likes < ?", 10)
# => <ActiveRecord::Relation [...]>

# Following query on execution would raise exception.
>> Post.joins(:comments).where("likes > 10")
# => ambiguous column name: id

Rails 6.1
>> Post.where("published_at >": Date.today)
# => <ActiveRecord::Relation [...]>

>> Post.find_by("likes <": 10)
# => <ActiveRecord::Relation [...]>

# Following query on execution would NOT raise exception.
>> Post.joins(:comments).where("likes >": 10)
# => <ActiveRecord::Relation [...]>

Comments