angular-restmod icon indicating copy to clipboard operation
angular-restmod copied to clipboard

Wrong url if fetch ($find) single item in nested resource

Open aburke85 opened this issue 8 years ago • 3 comments

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?

aburke85 avatar May 16 '16 18:05 aburke85

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?

ttonyh avatar May 31 '16 05:05 ttonyh

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 avatar Sep 27 '16 06:09 jpulec

@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?

spidergears avatar Nov 14 '18 22:11 spidergears