SundayMonday
SundayMonday

Reputation: 19737

Calling .all in Active Record query

I'm building an Active Record query over a few lines:

query = ForumThread.joins(:posts)
query = query.where(:posts => {:some_integer => 123})

No query is executed for results = query. However results = query.all works. What does call .all on the ActiveRecord::Relation do?

Upvotes: 1

Views: 2218

Answers (1)

Marc Talbot
Marc Talbot

Reputation: 2059

When you say

results = query

all you are doing is making results equal to the query object.

When you call

results = query.all

You are sending the all method to query (which says get all of the records that match the query) and assigning the result to results.

Upvotes: 3

Related Questions