data
data copied to clipboard
"content" field doesn't work through async relationships
(This is based off a forum question.)
Given these fields:
// app/models/answer.js
question: belongsTo('question'),
// app/models/question.js
content: attr('string'),
If you try to render the content
field through the async question
relationship, it doesn't work.
{{someAnswer.question.content}}
The expected output is the value of the content
field. The actual output is <frontend@model:question::ember276:5>
.
The PromiseProxy's own content
property takes precedence.
I don't think we can easily fix this without breaking other things, but we should consider at least linting for the content
field name in models.
Until we remove proxies, we could move .content
to a more private place, and expose .content
as deprecated and prioritize the user supplied one.
.content is intimate API at this point, I think adding “content” to the list of reserved property names is better for now until we have a stronger proposal for eliminating proxies.
@igorT @ef4 ~~I have a proposal, best seen as a PR~~
I looked into this and nvm. My idea was to proxy to a more private target, then change the proxy to check for content
on the target and return target
in the default case and target.content
in the case in which that property exists on the target. Unfortunately the extend of our use of ObjectProxy, ArrayProxy, and PromiseProxyMixin means we'd have to supply our own versions of all three of these things, which is a fairly substantial change we should not do.
Best we can do know is add it to the list of reserved property names, and at a future date remove it from that list once we have eliminated our use of these proxies.
I'll try to see if someone can pick up the work in https://github.com/emberjs/data/pull/5755 this week.
The scope of this issue is now only PromiseBelongsTo
, since we assert for content properties there's nothing more for us to do here. When we replace @ember-data/model
we will not use these older proxies.