I am trying to access a specific route with a specific field in my model.
Example: www.myPage.com/wedding/couple1 www.myPage.com/wedding/couple2
All examples that I found in Ember's community use ID, but I am trying to use another one (which I will make sure to be unique).
My route config:
Router.map(function() {
this.route('create-wedding');
this.route('weddings');
this.route('wedding', { path: 'wedding/:pageName' });
});
My link to the route:
{{#link-to 'wedding' wedding.pageName}}Access{{/link-to}}
Try to get the record:
model(params) {
return this.store.query('wedding', { orderBy: 'pageName', equalTo: params.pageName });
}
But, how to get the record for the specific param "pageName" in my Route model? And how to get the same record when the user access the page directly from the URL?
Thanks in advance
If your non-id field is really, truly unique (i.e. enforced uniqueness on the back end), you can use it as your front end id by writing a custom serializer.
export default DS.JSONSerializer.extend({
primaryKey: 'other_unique_key'
});
If you are using a REST back end, just swap out DS.JSONSerializer
for DS.RESTSerializer
in the code above.
This would allow you to closely follow Ember's conventions for record handling by id. You can read more about authoring custom serializers here in the Guides.
Another alternative is to use Query Parameters. In that case, your URL would look more like http://example.com/weddings?wedding=romeojuliet
Read more about Query Parameters and accessing their values here in the Guides.