Skip to content

Instantly share code, notes, and snippets.

@rubyonrailstutor
Last active December 16, 2015 14:09
Show Gist options
  • Save rubyonrailstutor/5446652 to your computer and use it in GitHub Desktop.
Save rubyonrailstutor/5446652 to your computer and use it in GitHub Desktop.
class Company < ActiveRecord::Base
attr_accessible :cb_url, :name, :url
validates_presence_of :name, :cb_url
validates_uniqueness_of :name
has_many :events, :uniq => true
end
@records = Company.joins(:events).where(:events => { :date => ("2013-1-22")..("2013-3-22") } ).count
1.9.3p374 :002 > @records = Company.joins(:events).where(:events => { :date => ("2013-1-22")..("2013-3-22") } ).count
(4.7ms) SELECT COUNT(*) FROM "companies" INNER JOIN "events" ON "events"."company_id" = "companies"."id" WHERE ("events"."date" BETWEEN '2013-1-22' AND '2013-3-22')
=> 786
#i'm getting 786 records but should only be getting 774, thoughts?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment