Ruby on Rails Wednesday, August 24, 2016

The first thing I do with it is this:

if @new_relationships.any?

So it looks like .any? affects the query? I would have thought rails would perform the query, get all the records into @new_relationships, and then count them. This is a surprising feature.

On Wednesday, August 24, 2016 at 1:26:54 PM UTC+1, Frederick Cheung wrote:

On Wednesday, August 24, 2016 at 1:11:42 PM UTC+1, Bazley wrote:
This rails/sql code...

    @new_relationships ='*')
.from("(#{@rels_unordered.to_sql}) AS rels_unordered")
                        INNER JOIN  relationships
                        ON = relationships.character_id
                        ORDER BY    relationships.created_at DESC

produces a query that begins like this:


Why is it counting the records?? I haven't asked for a count. I simply want to select all columns after the join:

The code you posted above doesn't actually run any query - queries are executed lazily. What are you doing with @new_relationships? 


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment