Computed Columns in SQL with ActiveRecord and Rails
September 17, 2009 by Dylan VaughnConsider the following scenario. You have a blog application, which has users, who have many posts. Posts, in turn, have many comments. Comments must be approved by the post author, so therefore can be in one of the following states, 'pending', 'approved', or 'denied'. In the admin interface, you would like to display a paginated list of users, sorted by the number of 'pending' comments are associated with their posts. How can you ask Rails for this information?
Typically, when wanting to operate on roll-up counts of related objects, such as how many users are in a group, or how many comments belong to a post, Rails would suggest that you use the counter_cache option in the association:
class Comment < ActiveRecord::Base
belongs_to :post, :counter_cache => true
end
Dylan Vaughn Engineering Manager
Read more from the Engineering category. If you would like to leave a comment, click here: Comment. or stay up to date with this post via RSS, or you can Trackback from your site.
Five Open Source Projects To Help You Write Better Code
May 11, 2009 by Dylan Vaughn
A significant factor to the success or failure of any software development effort is the quality of tools your team uses. While in the not-so-distant past many of the tools required were proprietary software packages, now open source projects dominate the landscape. Today I would like to discuss five projects that can significantly increase your team’s effectiveness. As is the case with many open source endeavors, each of these projects were inspired by other open source projects - either to make a good thing better, or fix what someone thought were irreconcilable issues with then-existing software.
Dylan Vaughn Engineering Manager
Read more from the Engineering category. If you would like to leave a comment, click here: Comment. or stay up to date with this post via RSS, or you can Trackback from your site.