ODataAngularResources icon indicating copy to clipboard operation
ODataAngularResources copied to clipboard

String typed keys

Open PatrickBorkowicz opened this issue 7 years ago • 2 comments

Absolutely love this repository; I have used it on three projects so far with great success. One thing though, my OData v4 APIs (in .NET) require entities with string typed keys be wrapped in single quotes when using this syntax:

/City('Toronto') as opposed to /City(Toronto)

That's not a problem when I'm calling the API directly, since I can just do this:

var myCity = City.odata().get("'" + cityName + "'");

but this won't work when using a method like $update, since it uses the value of whatever odatakey was specified when setting up the $odataresource.

I snuck this code into odataresources.js for now:

forEach(odatakeySplit, function (param) {
  // Original code.
  //params[param] = data[param];

  // If odatakey is a string, wrap in quotes.
  if (typeof data[param] === 'string')
    params[param] = "'" + data[param] + "'";
  else
    params[param] = data[param];
});

and it seems to work, but perhaps there is a better solution? Maybe when configuring $odataresource?

Thanks,

(Apologies if this this is not the right place to ask this.)

PatrickBorkowicz avatar Mar 24 '17 14:03 PatrickBorkowicz

think new $odata.Property(data[param])

oleg-demkovych avatar Jun 08 '17 12:06 oleg-demkovych

Was just reviewing this after running into a case with it myself. Looks like the suggested fix would probably break the case where the is embedded in the url (ie odata/path/to/:my/wierd/entity. Which looks like what the second if block seems to handle on lines 989 to 997. Probably the best place would be on line 987 Im guessing.

Scratch that, looks like your edit is correct and working good. Will do some more testing, add some karma tests and try and get a pull request setup for this if nobody else can see any issues with the change.

kyse avatar Jan 18 '18 02:01 kyse