Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: route serialize does not extract param off proxy #19298

Merged
merged 1 commit into from
Feb 3, 2021

Conversation

snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Dec 6, 2020

close emberjs/data#7380

name in model does not work with our content in a Proxy.

This does not work where tag is a ED relationship on @model.

<LinkTo @route="tag" @model={{@model.tag}}>{{@model.tag.title}}</LinkTo>
Uncaught Error: Assertion Failed: You attempted to generate a link for the "tag" route, but did not pass the models required for generating its dynamic segments. You must provide param `id` to `generate`.

// has() {
// return false;
// }
// });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this example here in case we wanted a more general solution vs the ObjectProxy (which more closely resembles Ember-Data relationship)

Comment on lines 65 to 67
} else {
object[name] = get(model, name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually this is pretty odd (e.g. if we were going to fall back to use get(model, name) then we shouldn't check name in model at the first branch above)

I think we could try to o something special like:

} else if (isProxy(model)) {
  object[name] = get(model, name);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue as long as the helper util doesn't check for a symbol-ish thing that EmberData can't easily make use of (e.g. it checks for the well known proxy methods) then I don't see an issue with doing it this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@runspired ya, its basically anything that uses the proxy mixin

@@ -63,6 +63,8 @@ export function defaultSerialize(
object[name] = get(model, name);
} else if (/_id$/.test(name)) {
object[name] = get(model, 'id');
} else if (isProxy(model)) {
object[name] = get(model, name);
Copy link
Contributor Author

@snewcomer snewcomer Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also put this in the first if expression. Up to you if you feel having this final else if is better. Or perhaps it doesn't matter 😄 .

@rwjblue rwjblue merged commit 38f1742 into emberjs:master Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using a belongsTo relationship in a LinkTo doesn't work
3 participants