0
c.models.car.findOne where: {id: 1}, (err, car)->
    car['seat'] = 1  #seat is not originally in the car object but I would like to add it
    car['color'] = 'red'  #color is originally in car and is changed
    console.log car

The issue is that color is being changed, but seat is not being added. When I do typeof car it returns object. Any ideas?

416E64726577
  • 2,214
  • 2
  • 23
  • 47
Alexis
  • 23,545
  • 19
  • 104
  • 143
  • Was `seat` a car attribute, but not assigned, or was it not an attribute at all to begin with? – zeantsoi Jun 17 '13 at 02:27
  • Is this a database query? – Blender Jun 17 '13 at 02:34
  • @Blender yes it is a db query – Alexis Jun 17 '13 at 02:34
  • @zeantsoi seat was not an attribute at all to begin with. I want to add it. But it is not "sticking" – Alexis Jun 17 '13 at 02:34
  • @Alexis: This isn't really a JavaScript question. It's an issue with your ORM, so tag it as such. – Blender Jun 17 '13 at 02:36
  • @Blender good call. Done. It is using jugglingdb and compoundjs. But I still think it is a js issue because the ORM is returning the right thing - an object with the right results. It seems like a js issue that I can't add a key to the object. – Alexis Jun 17 '13 at 02:38

1 Answers1

1

I think you are using an ORM which decline the assignment. Try to use this:

c.models.car.findOne where: {id: 1}, (err, car)->
    car = car.toObject(); # or car = JSON.parse(JSON.stringify(car))
    car['seat'] = 1  #seat is not originally in the car object but I would like to add it
    car['color'] = 'red'  #color is originally in car and is changed
    console.log car
luin
  • 2,077
  • 2
  • 20
  • 23