ember-django-adapter
ember-django-adapter copied to clipboard
Ember Route - Adapter with no content
Hello
I am with a 'little' problem to use ember-django-adapter.
I follow the instructions on docs, but when I call this.store.find('name') on my route, nothing is returned to template.
When I call this.store.query('name',{param1:123,param2:'abc'}), the meta attributes(pagination, count, etc) are populated, but content is not.
I don't know if it's a bug, or just my mistake. This is my configuration:
// adapters/application.js
import DRFAdapter from './drf';
export default DRFAdapter.extend({
addTrailingSlashes: false
});
// models/categoria.js
import DS from 'ember-data';
export
default DS.Model.extend({
nome: DS.attr('string'),
descricao: DS.attr('boolean'),
inclusao: DS.attr('date')
});
// routes/categoria.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export
default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() {
let result = this.store.query('categoria', {
page: 1
});
return result;
},
setupController: function(controller, model) {
console.log(model);
controller.set('content', model);
}
});
<!-- templates/categoria.hbs -->
{{outlet}}
<table>
{{#each model as |item|}}
<tr>
<td>{{item.nome}}</td>
</tr>
{{else}}
Sorry, nobody is here.
{{/each}}
</table>
Anyone can help me?
My environment:
Ember Inspector 1.9.3
Ember 1.13.7
Ember Data 1.13.8
jQuery 1.11.3
Ember Simple Auth 0.8.0
@ericktm use findAll instead of find.
this.store.findAll('categoria');
As for no records being returned, can you paste the output from your API? e.g., if your api is at localhost:8000/api/ run:
curl http://localhost:8000/api/categorias/
@ericktm You should also use the latest point release for Ember (1.13.10) and Ember Data (1.13.14). These versions have a lot of useful bug fixes.
@dustinfarris Hello, thank you for answer.
A changed to:
// routes/categoria.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export
default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() {
return this.store.findAll('categoria');
}
});
This is my response from server:
{
"count": 14,
"next": "http://hostapi.com/api/categoria?page=2",
"previous": null,
"results": [{
"id": 490,
"nome": "sssss",
"descricao": "",
"inclusao": "2015-10-21T23:46:58.064503Z"
}, {
"id": 491,
"nome": "ssssssss",
"descricao": "",
"inclusao": "2015-10-21T23:47:01.165067Z"
}, {
"id": 480,
"nome": "cadastro novo",
"descricao": "Edição de registro",
"inclusao": "2015-10-20T00:01:46.658718Z"
}, {
"id": 486,
"nome": "teste",
"descricao": "",
"inclusao": "2015-10-21T23:46:49.616188Z"
}, {
"id": 492,
"nome": "sssssss",
"descricao": "",
"inclusao": "2015-10-21T23:47:03.857929Z"
}, {
"id": 473,
"nome": "Brazil",
"descricao": "ergrg",
"inclusao": "2015-07-02T17:08:21.810887Z"
}, {
"id": 481,
"nome": "Food",
"descricao": "Gastos gerais relacionados à alimentação",
"inclusao": "2015-10-20T00:02:02.573066Z"
}, {
"id": 487,
"nome": "ssss",
"descricao": "",
"inclusao": "2015-10-21T23:46:51.563832Z"
}, {
"id": 475,
"nome": "Salário",
"descricao": "",
"inclusao": "2015-07-06T20:51:13.740509Z"
}, {
"id": 482,
"nome": "Expenses",
"descricao": "description",
"inclusao": "2015-10-20T02:45:27.682914Z"
}]
}
@benkonrath Thanks. I also upgrade packages to lastest versions. Ember 1.13.10 is not found. The last release from ember-cli repo is 1.13.8.
DEBUG: -------------------------------
ember.debug.js:5442 DEBUG: Ember : 1.13.8
ember.debug.js:5442 DEBUG: Ember Data : 1.13.14
ember.debug.js:5442 DEBUG: jQuery : 1.11.3
ember.debug.js:5442 DEBUG: Ember Simple Auth : 0.8.0
ember.debug.js:5442
DEBUG: -------------------------------
I noticed that your API endpoint does not have "s" on the end. Is Ember Data pluralizing this and adding an S which is why there are no results?
Can you check the 'network' tab in chrome and find the request that is being made and see if it is correct.
Checking with Chrome Inspector, the server is called GET method. The response is the same as returned when I use curl or SoapUI.
Do you have some example project using django-ember-adapter? Maybe this can help
There's not an example project that I am aware of. Can you create small project that demonstrates the issue that you are having? This will be the easiest way to for us help to investigate the problem. Thanks.
I 'll create a new project from zero in this weekend and publish into github for avaliation purposes.