Speeple News Search

Sign Up! | Tags | Domains | Statistics | Options | Advanced Search

Find users with at least 'n' items

m.onkey.org » 2008 » May » 1st » Find users with at least 'n' items

Tagged: tips, irc, activerecord

This question is asked quite a few times in #rubyonrails When your models look like : 1 2 3 4 5 6 7 class User < ActiveRecord::Base has_many :items end class Item < ActiveRecord::Base belongs_to :user end How do you find all the users with at least ‘n’ number of items ? Here’s how : User.find :all, :joins => " INNER JOIN items ON items.user_id = users.id " , :select => " users.*, count(items.id) Continue Reading »


Latest news from has_many :bugs, :through => :rails - Home:

  1. Sanity for free
  2. Poor man's migrations
  3. Active Record tips and tricks
  4. Rails does not block on file uploads
  5. Rescue from dispatching

Latest news from m.onkey.org:

  1. If you see this
  2. RSpec & COBOL
  3. Improve Rails Documentation
  4. Single file Rails Application
  5. Tidbits from my crap