question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Having a better understanding of one, all, get, and getList

See original GitHub issue

Hi there,

Can anyone lend a hand, I have a tough time understanding the difference between one,all,get and getList. I have a working product but I don’t think I am using it correctly so I decided to refactor it and then came to the conclusion that i really don’t understand when to use one over the other.

Here is what i understand

all > point to a collection ex var cars = Restangular.all(‘Stock/Cars’);

so if this points to a collection i presume I can do a getList() ? But getList() needs a sub element.

I have been doing a get() here as i need to pass in some querystring params and getListyou have to pass in a sub element which I don’t have.

the other thing I find confusing is the “one”, it states that one points just to one element, actually I get a list of Cars that are ford by doing the following

Restangular.one(‘Stock/Cars’, carType).get({colour: ‘red’}).then

As you can see I have built up a /Stock/Cars/Ford?colour=red (carType=Ford)

In the docs it states

   one(route, id): This will create a new Restangular object that is just a pointer to one element with the route route and the specified id.

I have used “one” to build up my call but it certainly doesn’t point to one element, I get a number of elements back.

I couldn’t seem to use the getList here as I had to pass in the sub element which i don’t have. so I used “get” which allows me to pass in some queryString params.

It states in the documentation

  get([queryParams, headers]): Gets the element.

which sounds like it just 1 element when in fact i get over 20 cars returned, so its not just element.

I hope somebody can help me here.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mgontocommented, Dec 5, 2013

This was working a returned a collection to me, and I was populating the collection but as we have already confirmed it should be geting “An” element a not a collection.

Why did it work ? 😃

So, it does work as it does the HTTP request. The difference is that all queries done with get and one expect an element, so I’m not restangularizing all elements.

When you call getList, I restangularize the list itself and then each of the elements. Getting a list with get works, but you won’t get the elements restangularized, and therefore, you won’t be able to call put or get on them.

I think thats alot cleaner than me do a /Stock/Cars 😃

I would anyway add the stock to the baseUrl. If you need to call it everytime, then set it to the base.

0reactions
iangregsondevcommented, Dec 6, 2013

Your welcome.I thinks its always a good idea to get other peoples opinions too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between .all() and .one() in Restangular?
The one() function has a second argument that accepts an id e.g. .one('users', 1) . one('users', 1).get() translates to /users/1 ...
Read more >
SharePoint Online REST API - Get List selecting all fields ...
Programmer - I understand that you can select fields explcitly, I am wondering about excluding fields explicitly. The reason being, if a field ......
Read more >
How to Convert pandas Column to List - Spark by {Examples}
You can get or convert the pandas DataFrame column to list using Series.values.tolist(), since each column in DataFrame is represented as a ...
Read more >
Get data with Cloud Firestore - Firebase
There are three ways to retrieve data stored in Cloud Firestore. Any of these methods can be used with documents, collections of documents,...
Read more >
findElement vs findElements in Selenium - BrowserStack
Now, let's delve deeper into understanding how to find web elements with the help of various locators. One can refer to different types...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found