Back to Course

Reading the Source · Card 8

What does has_many :posts actually add?

One line. A collection proxy with about twenty methods on it, plus class-level metadata. Most developers can name three.

The familiar line

Standard. You've written it. What does it generate?

class User < ApplicationRecord
  has_many :posts
end

The question

List every method has_many :posts adds to a User instance. The mid-level answer names user.posts and maybe one or two more. The senior answer is closer to twenty.

Take a moment. The reader (user.posts) is obvious. So is the writer. After that, think about: building, creating, counting, querying, checking emptiness, mutating.