Alloy.Collections.fetch({params}) doesn't work
adriendillens opened this issue · comments
Hi everyone !
Firstable, thanks to @jasonkneen and contributors for this awesome work ;-)
This is a very good job that you achieved !
I have placed the latest RESTe dist version into my lib/ folder.
I removed all Collection src="" and Model src="" tags
I also removed all files in models/ folder.
When i call api methods directly, it works (i can see the returned array) :
api.getUser({
login: $.username.value, password: $.password.value
}, function(user) {
Ti.API.info('user : ');
Ti.API.info(user);
});
But, when i try to fetch from read method, it doesn't (no error, but collection is always empty) :
Alloy.Collections.users.fetch({
login: $.username.value, password: $.password.value
});
Here is my (only) config file (placed directly in Alloy.js) :
api.config({
debug: true,
errorsAsObjects: true,
autoValidateParams: false,
validatesSecureCertificate: false,
timeout: 4000,
url: "http://myUrl/",
models: [{
name: "user",
// id: "objectId",
read: "getUser",
content: "results",
collections: [{
name: "users",
content: "results",
read: "getUsers"
}],
}],
methods: [{
name: "getUser",
get: 'ressources/person?login=<login>&password=<password>'
}, {
name: "getUsers",
get: 'ressources/person?login=<login>&password=<password>'
}],
onError: function(e, retry) {
Ti.API.info('error from reste');
},
});
With debug enabled, i can see the two requests sent, and they are exactly the same.
So, There's something wrong in my code, but i can't see what ^^.
Any help will be appreciated, thank you guys ;-)
I can't work on it today, but i know that fetch method is an async call, and i must log collection into a success callback function. Or, maybe, the content property of the config file that is not working properly.
You have no id specified in your model -- please specify the id field and then let me know.
hi @jasonkneen !
Thank you for your answer.
I will set the id in my model, and i will let you know ;-)
@jasonkneen Now, it works ;-)
I had many problems : id not defined, wrong content property and async response not properly handled (success callback not well placed in code).
You can close this issue.
Thank you again for your answer, and for your awesome work ;-)
no worries.