This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Message originally sent by slack user U721YFNO7M0
I’m struggling with how to remove associations.
My User has_many
budgets and my Budget belongs_to
If I follow the advice I’ve seen in here about either (putting them in the same pack. Not applicable), or deleting one of the associations directions, I remove the has many. In it’s place, on budget I add something like
class Budget < ApplicationRecord
def self.all_for_user(user_id)
Budget.where(user_id: user_id)
end
end
All that seems to do is replace instances of user.budgets
with Budget.all_for_user(user.id)
which still counts as a dependency from whoever is calling that to Budget.
Still trying to wrap my head around how that pattern solves the circular dependency issue.