Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember Route - Adapter with no content #146

Open
ericktm opened this issue Oct 27, 2015 · 9 comments
Open

Ember Route - Adapter with no content #146

ericktm opened this issue Oct 27, 2015 · 9 comments

Comments

@ericktm
Copy link

ericktm commented Oct 27, 2015

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?

@ericktm
Copy link
Author

ericktm commented Oct 27, 2015

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

@dustinfarris
Copy link
Owner

@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/

@benkonrath
Copy link
Collaborator

@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.

@ericktm
Copy link
Author

ericktm commented Oct 27, 2015

@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: -------------------------------

@dustinfarris
Copy link
Owner

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.

@ericktm
Copy link
Author

ericktm commented Oct 27, 2015

Checking with Chrome Inspector, the server is called GET method. The response is the same as returned when I use curl or SoapUI.

@ericktm
Copy link
Author

ericktm commented Oct 27, 2015

Do you have some example project using django-ember-adapter? Maybe this can help

@benkonrath
Copy link
Collaborator

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.

@ericktm
Copy link
Author

ericktm commented Oct 30, 2015

I 'll create a new project from zero in this weekend and publish into github for avaliation purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants