angular-restmod
angular-restmod copied to clipboard
Wrong url if fetch ($find) single item in nested resource
I have 2 models defined:
Blog:
restmod.model("/blog").mix({
posts: { hasMany: 'Post' }
});
Post:
restmod.model("/posts");
I use a slug as primary key for both models and only the combination is unique.
The request of all post uses the correct url (/blog/blogSlug/posts).
Blog.$new(blogSlug).posts.$refresh();
The request of a single posts of the nested resource uses the url of the unnested resource (/posts/postSlug)
Blog.$new(blogSlug).posts.$find(postSlug)
What I am doing wrong or how could i request the single post?
I'm having a similar issue; it doesn't feel like the expected behavior. Nested $find and $fetch should operate on the same URL path. Can someone confirm please?
If you wish for that behavior you need to defined Post
like so:
Post: restmod.model();
Note the absence of a scoped url for the Child relationship.
@jpulec thanks this works great.
Except for the cases when the Post
model is composite term like UserProgress
, this would generate /user-progresses
. Is there a work around or fix for this case to generate underscored url?