This is based on the use of Shopify's packwerk.
Asuming we have a posting
pack with a Post
model and a commenting
pack with a Comment
model, and
we want the commenting
pack to have a declared dependency on the posting
pack, then here's a pattern
to avoid the has_many :comments
usual declaration on the Post
model while still being able to have
very similar functionality to the dependent
option to react/restrict when a post is destroyed.
If you need to fetch a post's comments, you can simply use Comments.where(post: @post)
instead of the
usual @post.comments
. Same result. You can define a scope if you want to shorten it or something.