data icon indicating copy to clipboard operation
data copied to clipboard

"content" field doesn't work through async relationships

Open ef4 opened this issue 6 years ago • 4 comments

(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.

ef4 avatar Nov 01 '18 12:11 ef4

Until we remove proxies, we could move .content to a more private place, and expose .content as deprecated and prioritize the user supplied one.

igorT avatar Nov 02 '18 11:11 igorT

.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.

runspired avatar Nov 05 '18 17:11 runspired

@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.

runspired avatar Nov 21 '18 20:11 runspired

I'll try to see if someone can pick up the work in https://github.com/emberjs/data/pull/5755 this week.

runspired avatar May 21 '21 06:05 runspired

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.

runspired avatar Nov 20 '22 06:11 runspired