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.

.all().one() does not work for numbers

See original GitHub issue

This works:

> Restangular.all("models").one("1").getRestangularUrl()
/api/models/1

This also works:

> Restangular.one("models", 1).getRestangularUrl()
/api/models/1

But this triggers an error:

> Restangular.all("models").one(1).getRestangularUrl()
Error: You're creating a Restangular entity with the number instead of the route or the parent. You can't call .one(12)

Shouldn’t this be allowed for consistency reasons?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
pauldijoucommented, Aug 4, 2014

Sample 1 and 3 do not represent the same resource.

Restangular.all("models").one("1") means the sub-resource named 1 with currently no id inside the resource models (used to create an empty resource before doing a POST) while Restangular.all("models").one(1) would mean resource with id 1 inside collection models but that’s what Restangular.one("models", 1) is for, and nobody really wants to have two ways to do the same thing.

0reactions
diosneycommented, Mar 6, 2015

Same issue here, had to typecast to String in order to use it properly:

 if (instance_id) {
      return model
        .one(String(instance_id));
    }

+1 to @ntrrgc way of using it, like tasks.one(15).get(), and if a String, parse internally to number.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatically number rows - Microsoft Support
Add sequential numbers to rows of data by dragging the fill handle to fill a column with a series of numbers or by...
Read more >
SQL for ordering by number - 1,2,3,4 etc instead of 1,10,11,12
One way to order by positive integers, when they are stored as varchar , is to order by the length first and then...
Read more >
Why the number input is the worst input - Stack Overflow Blog
The list isn't long, but the issues are rather jaw-dropping. So here's a short list of all the horrible things about the number...
Read more >
Number - JavaScript - MDN Web Docs - Mozilla
Chrome Edge Number Full support. Chrome1. Toggle history Full support. Edge12. Toggl... EPSILON Full support. Chrome34. Toggle history Full support. Edge12. Toggl... MAX_SAFE_INTEGER Full support. Chrome34....
Read more >
How to use SUMIF function in Excel with formula examples
A good thing is that the function is available in all versions, from Excel ... When adding up numbers in one column based...
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