In Ruby/Rails, how to get current value of column of queried model in a different model class? -
i querying model within method in different model's class. how can refer queried model in sort of "rails way" preferably? please see code understand:
modela.where("id = ?", self.model_a_id).first.update_column(:attrbute_a, ???.attribute_a + self.attribute_b )
the "???" denotes how refer attribute model a. using self refer model b, class inside of.
you can way:
model = modela.find(model_a_id) model.update_column(:attribute_a, model.attribute_a + attribute_b)
btw, why don't use associations?
Comments
Post a Comment