Combine two ActiveRecord::Relation objects

Suppose I have the following two objects: first_name_relation = User.where(:first_name => ‘Tobias’) # ActiveRecord::Relation last_name_relation = User.where(:last_name => ‘Fünke’) # ActiveRecord::Relation is it possible to combine the two relations to produce one ActiveRecord::Relation object containing both conditions? Note: I’m aware that I can chain the wheres to get this behavior, what I’m really interested in … Read more

Rails ActiveRecord date between

I need to query comments made in one day. The field is part of the standard timestamps, is created_at. The selected date is coming from a date_select. How can I use ActiveRecord to do that? I need something like: “SELECT * FROM comments WHERE created_at BETWEEN ‘2010-02-03 00:00:00’ AND ‘2010-02-03 23:59:59′” 11 Answers 11

Understanding :source option of has_one/has_many through of Rails

Please help me in understanding the :source option of has_one/has_many :through association. The Rails API explanation makes very little sense to me. “Specifies the source association name used by has_many :through => :queries. Only use it if the name cannot be inferred from the association. has_many :subscribers, :through => :subscriptions will look for either :subscribers … Read more

Rails – Nested includes on Active Records?

I have a list of events that I fetch. I’m trying to include every user associated to this event and every profile associated to each user. The Users get included but not their profiles. How Would i do this Event.includes(:users [{profile:}]) The docs don’t seem to be clear: http://guides.rubyonrails.org/active_record_querying.html 3 Answers 3