I have two properties in my user model school_id
and school_name
because I allow users to specify their own school if the list I provide is not enough. This should be universal to a User
. The Ember documention seemingly suggests bindings but only provides aliased values or ones that need to be the same value. Observables seem appropriate, but what is best and how? Ideally, I'd like to specify this at the model level.
Models.User = DS.Model.extend({
schoolName: DS.attr("string"),
school: DS.belongsTo("school", {async: true })
});
What I want is that when I set schoolName
, school
is set to null, and when school
is set, schoolName
is set to null.
The Rails model equivalent of what I'm after:
class User < ActiveRecord::Base
def nces_high_school_id=(value)
write_attribute(:school_name, nil)
write_attribute(:school_id, value)
end
def school_name=(value)
write_attribute(:school_id, nil)
write_attribute(:school_name, value)
end
end