Created
October 25, 2011 11:23
-
-
Save benpickles/1312371 to your computer and use it in GitHub Desktop.
Finding model with custom IDs not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}); | |
}); |
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.
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
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