1

Here is my resource

var gamesRes = $resource('/collections/test13/:id', 
  {gameID: '@id'}
  );

and what i'm trying to do

  $scope.res = gamesRes.save({}, $scope.newGame);

If i'm setting isArray: true to save method it works fine. Strange thing is that i don't see, that $scope.res is really an array, in debugger it looks like an object

res:  { 
player1: sdf
player2: sdf
}

And I need to look like an object, not an array.

Also here is post method in server

app.post('/collections/:collectionName', function(req, res, next) {
  req.collection.insert(req.body, {}, function(e, results){
    if (e) return next(e)
    res.send(results)
  })
})

What i'm missing here?

arkhy
  • 447
  • 6
  • 18

1 Answers1

0

I believe if you look at what end point is being hit, you are not going to the one you think you are going to.

{gameID: '@id'} should probably be {id: '@gameID'} to indicate that the :id in /collections/test13/:id would map to gameIDattribute in the object you are saving.

Really, you are hitting your list endpoint (because the ID is being left off of the URL) and thus getting a list back.

TheSharpieOne
  • 25,646
  • 9
  • 66
  • 78
  • I think i didn't get what is it need for earlier. Anyway, i don't use it now, but i get the same error even if resource looks like var gamesRes = $resource('/collections/test13/'); – arkhy Sep 22 '14 at 20:38