I have a model similar Basket shown below. If customer_type is set
then it should also set customer to nil. Likewise, if I set customer,
it should inspect the customer_type attached to the customer and set
accordingly within Basket. However implementing it as below doesn't
seem to work.
Am I missing a better way to achieve this? I had also considered using
a before_save :set_customer_type kind of thing but felt the code may
loose a little readability. I'm coming from a Java world with
protected attributes, accessed via domain influence
methods, .set_customer, .process_order etc... I wasn't really sure how
best to interpret this into ruby on rails models.
class Basket < ActiveRecord::Base
customer_type = _customer.customer_type unless _customer.nil?