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

customGETLIST doesn't use setParentless correctly #1313

Open
Meekohi opened this issue Feb 3, 2016 · 6 comments
Open

customGETLIST doesn't use setParentless correctly #1313

Meekohi opened this issue Feb 3, 2016 · 6 comments
Labels

Comments

@Meekohi
Copy link

Meekohi commented Feb 3, 2016

It seems like setParentless should not change urls when dealing with collections, only single objects. Not sure if this is a documentation or code bug, but doesn't behave how I would expect:

Restangular.setParentless(['events']);
Restangular.one("calendars",1).all("events").customGETLIST("search",options);
// should make a request to //calendars/1/events/search
// since it is a collection and not an individual object,
// but makes it to //events/search instead
@Meekohi
Copy link
Author

Meekohi commented Feb 3, 2016

Note that this works:

Restangular.setParentless(['events']);
return Restangular.one("calendars",1).getList("events/search",options);

but you get "events/search" search objects instead of "events".

@pedromarce
Copy link
Collaborator

Hi @Meekohi, you are right, is the problem related to the use of customGETLIST or would the request also be wrong if you just ask for the events?

Restangular.one("calendars",1).all("events") // Calls //calendars/1/events or //events??

Thanks

@pedromarce pedromarce added the bug label Feb 16, 2016
@mcacek
Copy link

mcacek commented Feb 16, 2016

In my experience, the following is true.

Restangular.setParentless(['events'])
Restangular.one("calendars",1).all("events")

Results in a request to /events whereas I would have expected a request to /calendars/1/events

@pedromarce
Copy link
Collaborator

Thanks @mcacek, I agree, I have labeled as a bug, we'll try to get it fixed, but any PR would be much appreciated :)

@mcacek
Copy link

mcacek commented Feb 16, 2016

I'll see what I can do in regards to a PR.

@Meekohi
Copy link
Author

Meekohi commented Feb 16, 2016

Alas, this issue was big enough to bounce me back to ngResource. At a high level I think there is a big conflict in Restangular between the nice "auto-magic" routing and the reality of a complicated REST API. Some way to declare up-front what your resources and routes are would be really helpful toward getting clear expected behavior. For completeness, in this case the situation was:

GET /calendars/1/events         #the usual, works correctly
GET /calendars/1/events/search  #same endpoint but with ES backend. Not sure how to do this
PUT /events/1                   #needs setParentless to work correctly

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

No branches or pull requests

3 participants