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
- Later on, when we have a reference to the object that has the property
let abc = ref.get('someProperty'), make some changes via
abc.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
abcis the return value from our call to
get('someProperty')which was a
belongsToproperty), we get a
.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
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…?