This project is archived and is in readonly mode.
Lazy Loading broken since Beta3?
-
Ryan Bigg
I worked with Steve on this and couldn't confirm the behaviour either.
-
Dylan Markow
Weird -- I just tried it on another computer and same issue. Rails 3.0.0.beta2 does what it should, 3.0.0.beta3 does not. I tried it both on Ruby 1.9.1 and Ruby 1.9.2 (head), as well as both postgres and sqlite (all running on OS X). Here is the actual output from my rails console.
Beta 2 (no database queries made):
iMac [~/dev/lazy] rails c Loading development environment (Rails 3.0.0.beta2) ruby-1.9.1-p378 > posts = Post.order("title") => #<ActiveRecord::Relation:0x000001036b68e0 @table=#<Arel::Table:0x000001040a9c68 @name="posts", @table_exists=nil, @options={:engine=>#<Arel::Sql::Engine:0x0000010439e330 @ar=ActiveRecord::Base, @adapter_name="PostgreSQL">}, @engine=#<Arel::Sql::Engine:0x0000010439e330 @ar=ActiveRecord::Base, @adapter_name="PostgreSQL">>, @klass=Post(id: integer, title: string, body: text, created_at: datetime, updated_at: datetime), @implicit_readonly=nil, @loaded=nil, @limit_value=nil, @offset_value=nil, @lock_value=nil, @readonly_value=nil, @create_with_value=nil, @from_value=nil, @includes_values=[], @eager_load_values=[], @preload_values=[], @select_values=[], @group_values=[], @order_values=["title"], @joins_values=[], @where_values=[], @having_values=[], @arel=nil, @scope_for_create=nil, @order_clause=nil, @to_sql=nil, @last=nil, @first=nil, @join_dependency=nil, @should_eager_load=nil, @records=[]>Beta 3 (database query made):
iMac [~/dev/lazy] rails c Loading development environment (Rails 3.0.0.beta3) ruby-1.9.1-p378 > posts = Post.order("title") => [#<Post id: 1, title: "Post 1", body: "text", created_at: "2010-04-27 14:01:22", updated_at: "2010-04-27 14:01:22">, #<Post id: 2, title: "Post 2", body: "text", created_at: "2010-04-27 14:01:22", updated_at: "2010-04-27 14:01:22">, #<Post id: 3, title: "Post 3", body: "text", created_at: "2010-04-27 14:01:22", updated_at: "2010-04-27 14:01:22">, #<Post id: 4, title: "Post 4", body: "text", created_at: "2010-04-27 14:01:22", updated_at: "2010-04-27 14:01:22">, #<Post id: 5, title: "Post 5", body: "text", created_at: "2010-04-27 14:01:22", updated_at: "2010-04-27 14:01:22">]Please let me know what other details I could provide, or if you want me to try anything else specifically.
-
Jeremy Kemper
- Milestone cleared.
- State changed from new to open
-
Dylan Markow
After playing with it some more this morning, it appears that this is only happening in the console. Running the actual rails application server results in no database queries until I actually try to use the results.
So it seems that lazy loading is not enabled in the rails console as of Beta 3, but still works perfectly fine in a running app.
-
Jeremy Kemper
- State changed from open to invalid
irb calls
inspecton the result of a command, which will kick off a query. -
Neeraj Singh
@Dylan
As Jeremy said irb is calling inpsect on the value. If you want to suppress than then try
> posts = Post.order("title"); nilNotce nil at the end. In this way irb will not invoke inspect on posts. Hope that helps.
-
Dylan Markow
Thanks! I saw a recent commit for the Relation#inspect method, but didn't put two and two together since I had no idea that irb calls #inspect (though it makes perfect sense now that I know).