I am wondering if the counter_cache would work in single table inheritance.
For these models:
class User
has_many :questions
end
class Question
belongs_to :user, :counter_cache => true
end
class SimpleQuestion < Question
end
class ComplexQuestion < Question
end
So will the following counters work?
create_table(:users) do |t|
t.integer :questions_count
t.integer :simple_questions_count
t.integer :complex_questions_count
end
- All of them work
- None of them work
- Only
questions_count
work - Only
simple_questions_count
andcomplex_questions_count
Which one? I am guessing the 3rd, but I want 4 more. If it's not 4, how do I make 4 work?
=== UPDATE ===
Here is an example:
id, user_id, question_content, type
1, 3, something, SimpleQuestion
2, 3, something, SimpleQuestion
3, 3, something, ComplexQuestion
So now I want:
user.questions_count # => 3
user.simple_questions_count # => 2
user.complex_questions_count # => 1
My question is, what's the basic behavior of :counter_cache => true
and is it possible to apply on single table inheritance?