Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aburke85 opened this issue May 16, 2016 · 3 comments
Open

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

aburke85 opened this issue May 16, 2016 · 3 comments
Labels

Comments

@aburke85
Copy link

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?

@ttonyh
Copy link

ttonyh commented May 31, 2016

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?

@jpulec
Copy link
Contributor

jpulec commented Sep 27, 2016

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.

@spidergears
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants