David Heinemeier Hansson
2005-Apr-19 03:12 UTC
[ANN] Rails 0.12.0: Eager associations, new Base.find API, assertions revisited, more Ajax!
The time had come to butcher the piggy-back query and introduce real association loading through outer joins. Behold, the glorious eager loading of associations that makes it silly easy to fetch not 1, 2, but unlimited associations alongside any record in a single query. Turning 50 database queries into 1 never felt this good. # Turning N+1 queries into 1 for post in Post.find(:all, :include => [ :author, :comments ]) puts "Post: " + post.title puts "Written by: " + post.author.name puts "Last comment on: " + post.comments.first.created_on end Read more: http://ar.rubyonrails.com/classes/ActiveRecord/Associations/ ClassMethods.html (Scroll down to Eager loading of associations) And to match the eager loading, we''re introducing a brand new unified API for Base.find, which works the same whether you''re searching for a specific id, the first record, or all the records. By using named options we alleviate your poor brain for remembering whether the ordering option was argument number 3 or 4. Person.find(1, :conditions => "administrator = 1", :order => "created_on DESC") Person.find(1, 5, 6, :conditions => "administrator = 1", :order => "created_on DESC") Person.find(:first, :order => "created_on DESC", :offset => 5) Person.find(:all, :conditions => [ "category IN (?)", categories], :limit => 50) Person.find(:all, :offset => 10, :limit => 10) Read more: http://ar.rubyonrails.com/classes/ActiveRecord/Base.html#M000226 Better testing -------------- We''ve also slashed the huge number of assertions for testing controllers. In one fell swoop, we''ve gone from around thirty to a shap seven. The remaining assertions are more flexible than before, not nearly as hard to remember, and are followed on by the fantastic new assert_tag, which makes examining the HTML output of an action so much easier than the XHTML/REXML fumblings of yesterday. Read more: http://ap.rubyonrails.com/classes/Test/Unit/Assertions.html More Ajaxing ------------ Of course, we couldn''t make a new release without asserting the undisputed position as the number one framework for doing Ajaxed applications. This release contains a bunch of new smooth effects (http://mir.aculo.us/demos/effects/demo1.html) for visualizing your non-refreshing actions. It''s now much easier to make Ajaxed applications that treat the unfortunate without Javascript nicely with request.xml_http_request? and alternative targets for ajax links and forms. We''ve also added periodically_call_remote that can be used to Ajax-update a given block every so seconds. In the next release, which will be not very far off, we''re also adding awesome support for both Google Suggest-like search boxes and for upload progress indicators (http://sean.treadway.info/demo/upload). There''s a powerful team behind pushing the envelope on this. We have so not seen the end of it. A total of 96 changes, tweaks, and fixes ---------------------------------------- All these goodies are just the tip of the iceberg, though. There''s a total of 96 new features, changes, tweaks, and fixes packed into this monster of a release. And we didn''t even have time to push in all of the pending patches (http://dev.rubyonrails.com/report/3). How''s that for an action-packed three weeks since the last release? Fully backwards compatible! --------------------------- Despite the true onslaught of new features, fixes, and goodies, we''ve managed to keep this release fully backwards compatible with 0.11.1. So you just do a "gem update rails" and all the new stuff is available for use in your current application (to take advantage of the new JS effects you''ll want to copy that one over, though -- use rails . in your app dir to get that for free). See the changelogs for the full story: * Rails: http://api.rubyonrails.com/files/CHANGELOG.html * Active Record: http://api.rubyonrails.com/files/vendor/rails/activerecord/ CHANGELOG.html * Action Pack: http://api.rubyonrails.com/files/vendor/rails/actionpack/CHANGELOG.html * Action Web Service: http://api.rubyonrails.com/files/vendor/rails/aws/CHANGELOG.html * Action Mailer: http://api.rubyonrails.com/files/vendor/rails/actionmailer/ CHANGELOG.html * Active Support: http://api.rubyonrails.com/files/vendor/rails/activesupport/ CHANGELOG.html -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://www.loudthinking.com/ -- Broadcasting Brain
Michael Koziarski
2005-Apr-19 03:55 UTC
Re: [ANN] Rails 0.12.0: Eager associations, new Base.find API, assertions revisited, more Ajax!
On 4/19/05, David Heinemeier Hansson <david-OiTZALl8rpK0mm7Ywyx6yg@public.gmane.org> wrote:> The time had come to butcher the piggy-back query and introduce real > association loading through outer joins. Behold, the glorious eager > loading of associations that makes it silly easy to fetch not 1, 2, but > unlimited associations alongside any record in a single query. Turning > 50 database queries into 1 never felt this good.Congratulations to everyone involved in adding this great new feature. A seriously cool enhancement. It''s a fairly major change and there may well be bugs, once you''ve integrated eager associations into your applications please file bug reports for anything you notice. Another thing to consider is that the sooner you implement this functionality into your application, the more likely it is that we''ll fix any problems that you find. ;) http://dev.rubyonrails.org/ -- Cheers Your friendly Trac dweller.
Pelle Braendgaard
2005-Apr-19 06:36 UTC
Re: [ANN] Rails 0.12.0: Eager associations, new Base.find API, assertions revisited, more Ajax!
Congratulations to David and team for another fantastic release giving more than a few wows, while reading over the changelogs. I''ve upgraded with the only minor problem, which isn''t really a bug in my ActionMailer unit tests, where the new smart utf8 encoding messed around with my hardcoded expected subject. I fixed my code and it now works great. I cant wait to try the new effects and the eager loading of associations. This was another one that the Hibernate crew was using against us and is definitely a brilliant improvement. Regards Pelle
Stephen Waits
2005-Apr-19 06:36 UTC
Re: [ANN] Rails 0.12.0: Eager associations, new Base.find API, assertions revisited, more Ajax!
BRILLIANT!! Huge thanks to all contributers! --Steve
Hello, I encouter problem with flash.now when upgraded to 0.12. It''s not working anymore. Althoug normal flash is working. When I set it in controller and check it, it''s there but on the begining of the template (in layout) @flash is empty hash. I somehow feel it could be related to new partial rendering or maybe it''s just my own problem so I want to ask if somebody solves same problems. Thans alot. I even look in flash.rb but looks identical like older version, so nothing to see here. I will also continue with finding reason of this, so if you''ll give me some hints, it will be nice. Thanks alot. -- Pepe