It was brought to my attention by one of my developers and I confirmed it thru testing several of our models the following “problem”:
- We define our models with
belongsTo, likesomeProperty: belongsTo('model-name') - Later on, when we have a reference to the object that has the property
someProperty, welet abc = ref.get('someProperty'), make some changes viaabc.set("a","b")to the returned object (yes, it’s a valid object, not null, the object existed in the database, etc) - When we call
abc.save()(remember,abcis the return value from our call toget('someProperty')which was abelongsToproperty), we get aTypeErrorsaying.save is not a function:Uncaught TypeError: abc.save is not a function
Now, I realize that if we instead did abc.get('content').save(), that would work - it appears that the return from belongsTo properties are simply proxies, with a content property that has our actual model instance.
For now, my developers have resorted to just doing let abc = ref.get('someProperty.content'), but I can’t hep but feel that there’s got to be a better solution that getting what I presume is a “private” property.
How do we go about getting the actual model instance when we get() a belongsTo property, instead of that proxy object? Or should that proxy object also be proxying the .save() calls? Or did we miss some documentation somewhere that already covers this exact thing…?
Thanks, everyone!