ruby on rails - Reference data from current owner of relationship with ActiveRecord -
i have these models
class exercisesolving < activerecord::base belongs_to :exercise attr_accessor :important_data end class exercise < activerecord::base has_many :exercise_solvings def start #1 end end how can reference current exercisesolving @ #1, when call attributes this:
exercisesolving.first.exercise.start i need :important_data current relationship inside of described function. there clean way to this? directly passing exercisesolving instance exercise seems dirty me.
try adhere law of demeter , encapsulate behavior:
class exercisesolving < activerecord::base belongs_to :exercise attr_accessor :important_data def start exercise.solve(important_data) end end class exercise < activerecord::base has_many :exercise_solvings def solve(data) [...] end end @exercise_solving = exercisesolving.first @exercise_solving.start
Comments
Post a Comment