Skip to content

Instantly share code, notes, and snippets.

@benpickles
Created October 25, 2011 11:23
Show Gist options
  • Save benpickles/1312371 to your computer and use it in GitHub Desktop.
Save benpickles/1312371 to your computer and use it in GitHub Desktop.
Finding model with custom IDs not working
var Activity = Model("activity", function() {
this.persistence(Model.REST, "/activity");
this.unique_key = '_id';
});
$(function() {
Activity.load(function() {
console.log(Activity.all())
var one_activity = Activity.find('fa7043e52b644cd3a7a2217edc0e8928');
console.log(one_activity)
});
});
@a13x
Copy link

a13x commented Oct 25, 2011

Object
attributes: Object
activitys: Array[2]
0: Object
_id: "33156bf35c6245408e20f1e82f2971f9"
type: "something"
proto: Object
1: Object
_id: "fa7043e52b644cd3a7a2217edc0e8928"
type: "something else"
proto: Object
length: 2
proto: Array[0]
proto: Object
changes: Object
errors: Object
uid: "activity-1319549235167-0"
proto: Object

undefined

@benpickles
Copy link
Author

I think the problem is that the response should not have a root node. It should be like this:

[{ _id: "qwerty" }]

As opposed to:

{ activitys: [{ _id: "qwerty" }] }

Catering for this type of response is something I'd like to add.

@a13x
Copy link

a13x commented Oct 25, 2011

Hm, I'm going to double-check but I think my controller is returning a list of activities like this:
[{ "_id": "fa7043e52b644cd3a7a2217edc0e8928", "type": "something else"}, { "_id": "33156bf35c6245408e20f1e82f2971f9", "type": "something"}]. Does js-model add the root node somehow (is name of the model in model definition a factor)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment