Rails console restricts query output?

I am running rails in cloud9 IDE. I am running a query in the rails console which should just give me all the users in the custom table I created. It has 100 entries. However, when I run:

User.all

      

I get

 => #<ActiveRecord::Relation [#<User id: 1, name: "Expedita Eaque", group: 1>, #<User id: 2, name: "Omnis Vel Tempora", group: 3>, #<User id: 3, name: "Incidunt", group: 1>, #<User id: 4, name: "Aliquam", group: 3>, #<User id: 5, name: "Dolorum", group: 1>, #<User id: 6, name: "At", group: 2>, #<User id: 7, name: "Dignissimos", group: 1>, #<User id: 8, name: "Eligendi Amet Ut", group: 1>, #<User id: 9, name: "Corporis Sint", group: 5>, #<User id: 10, name: "Quis Explicabo", group: 1>, ...]> 

      

which is clearly not 100 records. How can I get the rails console to show me all the entries and not truncate, ...]>?

+3


source to share


1 answer


User.all

Returns an object ActiveRecord::Relation

, not actual results.

To view all entries, you can try

User.all.to_a

This behavior is purposeful and created for performance reasons. You can read more about lazy loading in ORM to better understand why.



Basically, you need to call a method on the AR relation object that really needs the underlying data, only then the request will be generated and executed.

EDIT

The console works a little differently with your application, the same as for any object that is returned in the console, it performs validation and writes truncated output. So, basically, it makes the query run on its own, but shows limited results for ease of viewing. To see all the results, use a method that will force the query to be executed and return the full result set.

+5


source







All Articles