Thanks for this one, as optimizing DB queries is always useful.
AND
Thanks for the funny (but true) "comments" in the screencast itself, you just made my day ^^
You can add this 2 lines
require 'hirb'
Hirb::View.enable
to your environment.rb :)
Great screencast as usual !
Though I have one question about your groups show view. How does this work ?
<%= render @group.comments %>
I never saw anything like this and the rails doc about render don't mention it.
Thanks btw !
Thanks for the screencast! I've been wondering when to use either :join or :include. Good stuff. :)
Really great screencast. Haven't really thought about the consequences of include and joins before.
Sorry for asking such a non related question , but how could u show the results in console in columns and showing queries too ? i was running the application and showing results after hitting console b4 , any help would b highly appreciated ....
got a cold Ryan ?
thanks for your useful tips, I really like your "scoped" trick for chaining custom methods.
To nest has_many through relationships, try passing the distinct keyword to the select query:
http://ultra.bohe.me/post/199125574/
Great episode like always.
Haven't heard about the about the 'scoped' method before. Thanks
Going back to basics, how did you get your user model into irb? I can do this easily with script/console but if I try User.all i get an uninitialized constant "User" error. Is there a way to have IRB auto load your models like script/console ??
@kiko The very top of the code Ryan posted in the show notes should cause the DB queries to show... I think this is the line you need:
ActiveRecord::Base.logger = Logger.new(STDOUT) # to show logs
Take a look at the link to Hirb in the show notes or at daG's comment to show the DB query results as a table.
Thanks for another great screencast Ryan. You know, I actually look forward to Mondays because of you.
Ryan, there is an important difference between :include and :joins that you didn't mentioned:
:include does a LEFT JOIN, whereas :joins does an INNER JOIN. Because an INNER JOIN requires matches in both tables, it can NOT be used if the second table has no entries for some records of the first table - because they will be filtered out.
So, IMHO your example "User.all(:joins => :comments, ..." is not a good one. The result will hide users which have no comments at all, so it doesn't result a full user list. In this example you should use :include instead of :joins.
Georg(e)? above is absolutely correct. Thank you by the way Ryan. This was exactly what I was looking for at this exact time, your screencasts are always great! Keep it up!
Hi Ryan,
Again nice screencast!!!
BTW I totally agree with @John.
Please add some captcha like things to stop spamming.
one personal question I want to ask you that have you ever think to change CSS of railscasts.com?
Though it is nice but yet it is same as when it launched.
@Georg
Joins allows a SQL fragment, so you could write :joins => "LEFT JOIN comments ON ...", according to the Rails documentation.
User.all(:joins => :comments, :select => "users.*, count(comments.id) as comments_count", :group => "users.id")
Ouch, don't do that or your code will not work on Oracle for example, in proper SQL, "group by" expression must contain ALL columns not in computed value (SUM, COUNT, etc..)
I noticed that if you use a select that joins the users table and the comments table, and create a comments_count attribute for accessing the number of comments for each user, there is a problem:
If that user has no comments, they will not be selected. Is there an obvious way around this? I imagine the select method just shouldn't be used if you want to find users who have not commented....
Я не понял что это за язык??
Хотя я знаю много языков программирования
Take advantage of 4unfl.com's exclusive online discounts and promotions on all of our men's and women's nfl jerseys, kids' and youth jerseys, and classic throwback football jerseys.
Three blonde women were stranded on an island. While trying to dig their way out, one of them came across a buried lamp. Suddenly a genie appears and offers to grant each one of them one wish, in return for saving him.
We’re big fans and Nike Air Max 2010 shoes is the best. The response of cushioning and flexibility, while the <a href="http://www.airmaxgoshopping.com/"><strong>Nike Free Run</strong></a><p>
<a href="http://www.airmaxgoshopping.com/nike-free-run-c-44.html"><strong>Nike Free Run+Running</strong></a>
<a href="http://www.airmaxgoshopping.com/"><strong>Nike Lunar Glide</strong></a><p>
are lightweight. The style is a fan of sports and athletes governors. The word is not enough, we enjoy your column shoes air max.
web tasarımı, kurumsal site tasarımı, profesyonel web sitesi tasarımı, profesyonel web tasarımı
<a href="http://www.webtasarimturk.net" title="web tasarımı">web tasarımı</a>
Great!This article is creative,there are a lot of new idea,it gives me inspiration.I think I will also inspired by you and think about more new ideas
This is a good,common sense article.Very helpful to one who is just finding the resouces about this part.It will certainly help educate me.
What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.
Any member of your group can post to your trip blog. This is a great way to share information with your team and your<a rel="follow" href="http://www.ejaisolar.com/" rel="nofollow">solar water heater</a> supporters.
It's one of the most important facto to fix this time.
Thanks a lot for sharing. You have done a brilliant job. Your article is truly relevant to my study at this moment, and I am really happy I discovered your website. However, I would like to see more details about this topic. I'm going to keep coming back here.
wow..its a great fun here....which i have done today through pdf format.Your blog is very much useful and rocking dear. you have provided detailed knowledge and information about today's latest technologies, online communications and other businesses.
Thanks a lot for sharing. You have done a brilliant job. Your article is truly relevant to my study at this moment, and I am really happy I discovered your website. your post are very helpful for me
look forward more posts
Perhaps this is one of the most interesting blogs that I have ever seen. Interesting article, Funny comment. Keep it up!
Discount Wholesale Electronics, Wholesale Cell Phones, Electronic Gadgets and More from the Best Dropship Wholesaler
It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
I have always liked Outdoor movies, a child standing at the window, looked out from home
to the following. Will be able to see the staff busy figure, a huge white cloth has a
child hang up and soon will be able to see the movie.
thanks for your useful tips, I really like your "scoped" trick for chaining custom methods.
I think this is a great post. One thing that I find the most helpful is number five. Sometimes when I write, I just let the flow of the words and information come out so much that I loose the purpose. It’s only after editing when I realize what I’ve done. There’s defiantly a lot of great tips here I’m going to try to be more aware of.






