Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Model says "someProperty: belongsTo('model-name')" but "get('someProperty').save()" doesn't exist

$
0
0

@josiahbryan wrote:

It was brought to my attention by one of my developers and I confirmed it thru testing several of our models the following “problem”:

  1. We define our models with belongsTo, like someProperty: belongsTo('model-name')
  2. Later on, when we have a reference to the object that has the property someProperty, we 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)
  3. When we call abc.save() (remember, abc is the return value from our call to get('someProperty') which was a belongsTo property), we get a TypeError saying .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!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles