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

Using a belongsTo relationship in a LinkTo doesn't work #7380

Closed
mansona opened this issue Nov 10, 2020 · 1 comment · Fixed by emberjs/ember.js#19298
Closed

Using a belongsTo relationship in a LinkTo doesn't work #7380

mansona opened this issue Nov 10, 2020 · 1 comment · Fixed by emberjs/ember.js#19298

Comments

@mansona
Copy link
Member

mansona commented Nov 10, 2020

Description

I noticed this while working on a recent change in empress-blog to try and workaround an issue where we can't rely on the sort order of hasMany relationships

Essentially this issue is quite simple to explain, and I have a feeling that it is one of those issues that quite a few people might be facing but because the workaround is so simple it likely gets overlooked. In my case it would end up being a breaking change to empress-blog and something that bleeds into the empress-blog-template ecosystem 🙈 so I would prefer to avoid the "workaround" of saying "just pass the id into the link".

The situation is that I have a post object that has a relationship to primaryTag and I want to link to the "tag page" of the primaryTag (showing all other content with this same tag) and I try to do something like this:

<LinkTo @route="tag" @model={{@model.tag}}>{{@model.tag.title}}</LinkTo>

but when you do that you get the following in the console:

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

Reproduction

I created a github repo with a simple reproduction, and a PR that "introduces the bug" to the main branch 😂

mansona/ember-data-bug-reproduction#1

It is being deployed to netlify so you can see it doesn't work if you check the preview deploy 👍

Versions

➜  ember-data-relationship-link git:(main) npm list ember-source && npm list ember-cli && npm list ember-data
[email protected] /Users/mansona/temp/ember-data-relationship-link
└── [email protected]

[email protected] /Users/mansona/temp/ember-data-relationship-link
└── [email protected]

[email protected] /Users/mansona/temp/ember-data-relationship-link
└── [email protected]

Note: I have tested this (using ember-try) on lots of other versions of ember and ember-data, this test app just seems a little behind. Let me know if you would like me to test this in a more recent ember-data 👍

@snewcomer
Copy link
Contributor

@mansona Hi Chris! Thx for the issue. This looks to be a bug in serializing Ember routeInfos when the target is a Proxy where key in target fails. I put up a quick PR (will come back and check the tests before my comp shuts down).

emberjs/ember.js#19298

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 a pull request may close this issue.

2 participants