About generated methods for has_many relations
Published on March 04, 2022
class Post
end
class Author < ApplicationRecord
has_many :posts
end
Besides making the collection of objects available through author.posts
16 more methods get added to the model automatically.
# Even when you add a post_ids column to the author model, the value is never persisted ;)
# Only foreign_keys on related models get updated accordingly!
author.post_ids == author.posts.map(&:id)