0

Im building an Ember app "ember-cli": "2.4.3", sitting on Laravel/Lumen and cant seem to get the wires hooked up correctly. Im trying to also an API server JSON-API compliant, so I have access to alter the syntax if thats a problem.

If I remove the export default DS.JSONAPISERIALIZER, I get ember.debug.js:32116 TypeError: typeClass.eachTransformedAttribute is not a function

With it, I typically get Assertion Failed: You tried to load all records but your adapter does not implement findAll

If I call getJSON(...) from within the route, instead to calling the store for the data, it works perfectly, and displays to the view as expected.

I have tried other adapters but I think that being JSON-API compliant I need to use the JSONAPIADAPTER. Any help would be awesome.

application.js

import DS from "ember-data";

export default DS.JSONAPIAdapter.extend({
 namespace: 'v1',
 host: 'http://edu-api.app:8000',
});

export default DS.JSONAPISerializer.extend({
 //in preparation of underscores in returned data
 //   keyForAttribute: function(attr) {
 //     return Ember.String.underscore(attr);
 //   },
 //   keyForRelationship: function(attr) {
 //     return Ember.String.underscore(attr);
 //   }
});

skill.js

import DS from 'ember-data';
var App = window.App = Ember.Application.extend();
var attr = DS.attr;

App.Skill = DS.Model.extend({
  name: attr("string"),
  desc: attr("string")
});

index.js

export default Ember.Route.extend({
  model() {
    //return this.store.findAll('skill');  //<- Assertion Failed: You tried to load all records but your adapter does not implement `findAll`
    this.get('store').findAll('skill');  //<- Assertion Failed: You tried to load all records but your adapter does not implement `findAll`
    //return Ember.$.getJSON('http://edu-api.app:8000/v1/skills'); //<- works, and properly displays data to view
  }
});

1 Answer 1

0

I think you primary have problems understanding ember-cli.

First you don't put your adapter and serializer in the same file. Maybe use the generators to get a default file like ember generate serializer application.

Your application serializer goes to app/serializers/application.js, your adapter to app/adapters/application.js.

Next this line looks really really wrong:

var App = window.App = Ember.Application.extend();

This creates a new app, but you should do this only once in your app/app.js. Next you use a global export, what you should never do in an ember-cli app.

To specify your model you need to locate your file under models/skill.js. There you don't attach your new Model to a global exported App like App.Skill = DS.Model.extend({, but you export it as default export like export default DS.Model.extend({.

Your index.js looks right if its located under routes/.

I strongly recommend you to read more about the ember resolver, and the ember dependency injection framework which do all this magic for you. Also use the generators to get your files, it can help you to place your files right.

Sign up to request clarification or add additional context in comments.

4 Comments

thans lux, Im going through your suggstions closely. I actually have the serializer and the adapter in the correct folders. The one thing I should have mentioned is that I used the generators to create the vanilla app and moved it into the lumen framework, I doubt that makes any differece.
Well but you use the ember-cli build step and development server I hope? I recommend to split your backend and your frontend, so your Laravel/Lumen doesn't matter at all. Just for production you build it together.
"The one thing I should have mentioned is that I used the generators to create the vanilla app and moved it into the lumen framework, I doubt that makes any differece." You have to build your app before deploying it to Lumen.
This line really got me in the right direction! export default DS.Model.extend({

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.