Created
May 25, 2011 15:59
-
-
Save arbarlow/991240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Release < ActiveRecord::Base | |
has_many :songs | |
end | |
# Tell Rails, update a "songs_count" field on the parent record after creation/deletion | |
class Song < ActiveRecord::Base | |
belongs_to :release, :counter_cache => true | |
end | |
r = Release.first | |
r.songs_count # No SQL is called for the count. Just uses the attribute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment