Cannot pass hash helper to link-to (EmptyObject lacking hasOwnProperty)
See original GitHub issueSometimes a route can resolve with multiple records like so:
model() {
const profile = ...;
const user = ...;
return RSVP.hash({
profile,
user,
});
},
So then you’d think you could use link-to like so:
{{link-to 'My Profile' 'profiles.show' (hash user=user profile=profile)}}
This doesn’t work because the hash helper returns EmptyObject and extractQueryParams tries to call .hasOwnProperty() on it, resulting in an error.
There’s a workaround to this which involves using an action with transitionTo but it feels like a poor experience.
This is an issue I’ve had with Ember for years. What’s the correct way to pass multiple records to link-to if not this?
I’m using ember-cli 3.0.2.
Edit: I’ve started using the following helper in place of hash as a workaround:
import { helper } from '@ember/component/helper';
export function plainObject(params, hash) {
const object = {};
// NOTE: `hash` is an `EmptyObject` so we convert to a POJO so that it can be
// used with `link-to`.
Object.keys(hash).forEach(k => object[k] = hash[k]);
return object;
}
export default helper(plainObject);
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Which object does not have `hasOwnProperty` in JavaScript?
Trying to look up a custom property in later code fails because a new, different wrapper object, lacking the custom property, is used...
Read more >rollup.js
This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project....
Read more >password_hash - Manual - PHP
password_hash() creates a new password hash using a strong one-way hashing algorithm. ... The "add note" rules of php.net say I can't link...
Read more >JavaScript Hash Table – Associative Array Hashing in JS
This tutorial will help you understand Hash Table implementation in JavaScript as well as how you can build your own Hash Table class....
Read more >Why are hash functions one way? If I know the algorithm, why ...
Let me invent a simple "password hashing algorithm" to show you how it works. Unlike the other examples in this thread, this one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Define standard… It works right now but it’s been decided that in general it’s not a good pattern and in the future it might be no longer supported.
There was at least one RFC related to this, maybe more: https://github.com/emberjs/rfcs/pull/283
@mhluska Are you able to create a test replicating the issue?
@mhluska - I’m actually unable to reproduce the original issue, I wrote a test that should have failed but didn’t: