Is there a way to find a record not by id. but via slug property.
Still I want to keep ids in store as primary key.
if my route is “/post/:slug” then I want to fetch record by slug from API.
Also I’d like to search the store if the record with the same slug already exists.
Can you advice something on implementation? I think that’s pretty common usage (with slugs), but unfortunately I got no ideas how to get this done right.
@lookingsideways Thanks, I had similar thoughts with fetching item by query and resolving it into one record. Unfortunately something didn’t work for me (maybe I misuse promises of 1.0beta). Your solution can be improved if a map for “slug” => “id” is created, so models can be cached by their slug.
Anyway, I decided to follow KISS and set the slug as the primary key for my records.
That simplified code. In my project I have opportunity to get non-unique slugs, depending on a project. Thus, I will clean up store on switching a project.