Skip to content

Instantly share code, notes, and snippets.

@thatguyintech
Created November 21, 2017 00:17
Show Gist options
  • Save thatguyintech/9ff551b0cbb6b27275cea438ea75534d to your computer and use it in GitHub Desktop.
Save thatguyintech/9ff551b0cbb6b27275cea438ea75534d to your computer and use it in GitHub Desktop.
# answer.rb
class Answer < ApplicationRecord
belongs_to :user, counter_cache: true
end
# user.rb
class User < ApplicationRecord
has_many :answers
end
# schema.rb
create_table "users", force: :cascade do |t|
# ...
t.integer "answers_count"
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment