I have a “Profile” model and two ActiveRecord::Relations of this model. SQL request of first relation is very big. Second is
Profile.where(:id => 1)
I want to add second relation to first. So, as a result, second relation will contain first prrofile.
I tried to
first.merge(second)
but it returns empty relation. Rails version is 3.2.2
Of course, result should be relation, too. I need to add .limit() and .paginate() to this relation.
You can tack additional .where clauses onto an existing relation, thus:
This will combine the new ‘where’ with any existing one using AND. ActiveRecord::Relation doesn’t support joining ‘wheres’ with OR, if you need to do that, check out Squeel (https://github.com/ernie/squeel) if you’re on Rails 3.1+, or meta_where (https://github.com/ernie/meta_where) for 3.0.