oskarrough / ember-wordpress

The bridge between Ember.js and Wordpress
http://ember-wordpress.surge.sh
MIT License
95 stars 26 forks source link

If adapter is defined , ember-wordpress fails #33

Closed v3ss0n closed 6 years ago

v3ss0n commented 7 years ago

It can't find it normally , so i tried importing but that also fails:

// app/models/post.js
import DS from 'ember-data';
import PostModel from 'ember-wordpress/models/post';
export default PostModel.extend({
  myNewProperty: DS.attr()
});
ember.debug.js:27778 Error while processing route: dashboard Could not find module `ember-wordpress/models/post` imported from `client/models/post` Error: Could not find module `ember-wordpress/models/post` imported from `client/models/post`
    at missingModule (http://localhost:9999/assets/vendor.js:248:11)
    at findModule (http://localhost:9999/assets/vendor.js:259:17)
    at Module.findDeps (http://localhost:9999/assets/vendor.js:199:24)
    at findModule (http://localhost:9999/assets/vendor.js:262:11)
    at requireModule (http://localhost:9999/assets/vendor.js:29:15)
    at Class._extractDefaultExport (http://localhost:9999/assets/vendor.js:117690:20)
    at Class.resolveOther (http://localhost:9999/assets/vendor.js:117403:32)
    at Class.superWrapper [as resolveOther] (http://localhost:9999/assets/vendor.js:55153:22)
    at Class.resolve (http://localhost:9999/assets/vendor.js:20567:35)
    at resolve (http://localhost:9999/assets/vendor.js:17962:36)
MartinMalinda commented 7 years ago

I import it the same way in 2.11-beta and it works correctly. I'd try nombom just in case the plugin wasnt installed successfuly.

v3ss0n commented 7 years ago

i am testing on 2.10 , ok i will try nombom.

oskarrough commented 7 years ago

Hi @v3ss0n thanks for reporting. But I also can't reproduce it. Did nombom work? Otherwise if you can make a test case or show the repo, that'd be great.

v3ss0n commented 7 years ago

@oskarrough i found the problem. i did a new ember app and tested ember-wordpress , and working fine , what it doesn't work is when application had defined own adapter. In our production we are using REST so it looks like this.

//adapters/application.js
import DS from 'ember-data';
import ENV from '../config/environment';
if (ENV.environment === 'development') {
  var host = ENV.localHost
} else if (ENV.environment === 'production') {
  var host = ENV.remoteHost
}

export default DS.RESTAdapter.extend({
  host: host,
  hexColorsArray: ['#fcb851', '#e64053', '#55bcb6', '#77edb2'],
  ajax(url, method, hash) {
    hash = hash || {};
    hash.crossDomain = true;
    hash.xhrFields = {
      withCredentials: true
    };
    return this._super(url, method, hash);
  }
})

then it tried to access http://host:port/posts , ignoring what defined in environment.js

oskarrough commented 7 years ago

If it helps, you can try to extend the ember-wordpress adapter. In your example above the namespace for the WP-API seems to be misisng.

https://github.com/oskarrough/ember-wordpress/blob/master/addon/adapters/wordpress.js

v3ss0n commented 7 years ago

As soon as i install ember-wordpress , all others models are having trouble:

        question: this.store.query('latestquestion', param),
        post: this.store.findAll('post')
Error while processing route: login Assertion Failed: You must include an 'id' for latestquestion in an object passed to 'push' Error

it all works fine without ember-wordpress , its a bug?

oskarrough commented 6 years ago

@v3ss0n could very well be. But since it apparently only affects Ember 2.10? I won't take the time to support it. If anyone wants to they are very welcome :)