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

Problems with latest ember-data 1.0.0-BETA.3 #96

Open
sarus opened this issue Oct 18, 2013 · 11 comments
Open

Problems with latest ember-data 1.0.0-BETA.3 #96

sarus opened this issue Oct 18, 2013 · 11 comments

Comments

@sarus
Copy link

sarus commented Oct 18, 2013

I tried updating the ember-data.js file in /js/vendor to the latest 1.0.0-BETA.3.

Unfortunately the generated app.js file and store.js no longer seems correct for the latest ember-data and I can't seem to figure out what I need to change.

Right now I'm just using FIXTURES to load test data. I know we should not have to specify the revision anymore or make calls to registerAdapter. In fact, based on the Models guide it seems like all you need to do is include ember-data and then extend DS.Model with your own models.

Has anyone successfully used ember-tools with the latest ember-data? What changes are required to app.js, store.js and the structure (if any) to get this working? Thank you!

@fivetanley
Copy link
Collaborator

Thanks for reporting the issue, we'll look at it as soon as we can!

@MiguelMadero
Copy link
Contributor

@sarus I'm using ember-tools with the latest ember-data. Did you also update ember.js (I'm using Version: v1.1.0-beta.4)

@MiguelMadero
Copy link
Contributor

Also I remember I also had to manually update localstorage_adapter (in case you're using that).

@MiguelMadero
Copy link
Contributor

Ohh and I also changed store.js.

The revision isn't needed and we just give it a reference to the adapter instead of creating it.

// by default, persist application data to localStorage.
require('../vendor/localstorage_adapter');

module.exports = DS.Store.extend({
  //adapter: DS.RESTAdapter
  adapter: DS.LSAdapter     // todo: review security considerations. Other users on the machine can access this data. This is no worse than accesing his account after they set `remember_me`.
  // adapter: DS.FixtureAdapter
});

@MiguelMadero
Copy link
Contributor

Actually there's just a PR.
#97

You could clone that repo and create the app by calling path/to/clonedrepo/bin/ember create your-app-name until it's merge.

@sarus
Copy link
Author

sarus commented Oct 19, 2013

I was still using Ember 1.0.0 so I went ahead and dropped in Ember 1.1.0-BETA.4 into the vendor folder. I'm using the FixtureAdapter so I manually updated config/store.js based on your PR so it now looks like:

module.exports = DS.Store.extend({
  adapter: DS.FixtureAdapter
});

Fnially, my config/app.js looks like:

// require other, dependencies here, ie:
moment = require('../vendor/moment');

require('../vendor/jquery');
require('../vendor/bootstrap.js');
require('../vendor/handlebars');
require('../vendor/ember');
require('../vendor/ember-data'); // delete if you don't want ember-data

var App = Ember.Application.create();

App.Store = require('./store'); // delete if you don't want ember-data

module.exports = App;

The app seems to build fine but it doesn't load and I get the following error:

Error while loading route: TypeError {} application.js:12320
(anonymous function) application.js:12320
Ember.Router.reopenClass._defaultErrorHandler application.js:42773
triggerEvent application.js:42723
trigger application.js:41846
handleError application.js:42108
invokeCallback application.js:20028
(anonymous function) application.js:20082
EventTarget.trigger application.js:19851
(anonymous function) application.js:20153
DeferredActionQueues.flush application.js:17383
Backburner.end application.js:17469
Backburner.run application.js:17508
executeTimers application.js:17731
(anonymous function)

I'm guessing I'm using the new ember-data incorrectly (if I switch back to the old ember and ember-data everything was working fine). I know the above console error isn't very useful but do you notice something I'm missing or doing wrong in getting everything setup? The app doesn't load at all (just a blank browser) so I'm not sure where to look for the issue.

Appreciate your assistance.

@MiguelMadero
Copy link
Contributor

Can you share routes.js? Also, I'm using the LSAdapter, could you try switching just to pin down the problem?

@sarus
Copy link
Author

sarus commented Oct 19, 2013

This is my routes.js. Switched to LSAdapter after updating it based on your PR but still get the same error.

var App = require('./app');

App.Router.map(function() {
  /*
   * When the user navigates to /alert render the alert template
   * When theu ser navigates to /alert/<alertID> render the details
   * template.
   */
  this.resource('alerts', { path : '/alerts'}, function(){
    this.resource('details', {path : '/:alert_id'});
  });  
});

@sarus
Copy link
Author

sarus commented Oct 19, 2013

Well I'm starting to think that the problem is with all the changes in ember-data when moving to 1.0.0-BETA.3. I checked this document which shows the transitions required (https://github.com/emberjs/data/blob/master/TRANSITION.md). Based on the transitions document it seems like setting up the store only requires one line:

App.ApplicationAdapter = DS.FixtureAdapter

and so store.js isn't really needed and app.js would become:

require('../vendor/jquery');
require('../vendor/handlebars');
require('../vendor/ember');
require('../vendor/ember-data'); // delete if you don't want ember-data

var App = Ember.Application.create();
App.ApplicationAdapter = DS.FixtureAdapter;

module.exports = App;

When declaring your models you also have to use the shorthand name of the model which I wasn't:

So comments: DS.hasMany('comment') instead of comments: DS.hasMany('App.Comment'). After making these changes I'm still having errors with the app loading but I'm guessing it's not an ember-tools issue at this point.

@sarus
Copy link
Author

sarus commented Oct 19, 2013

Okay, got things working. I followed the ember.js getting started guide and downloaded the two files linked in that document:

ember.js -> http://builds.emberjs.com/tags/v1.0.0/ember.js
ember-data.js -> http://builds.emberjs.com/tags/v1.0.0-beta.3/ember-data.js

My suggestion would be to stick with the versions of ember and ember-data used in the official ember guide rather than including ember-1.1.0 so that ember-tools is in sync with the documentation most new ember users will be following.

This is all I needed for my app.js file (when using the FixtureAdapter), and I did not need store.js anymore:

require('../vendor/jquery');
require('../vendor/bootstrap.js');
require('../vendor/handlebars');
require('../vendor/ember');
require('../vendor/ember-data'); // delete if you don't want ember-data

var App = Ember.Application.create();

App.ApplicationAdapter = DS.FixtureAdapter;

module.exports = App;

Thank you for all your help! The Ember community is really fantastic and supportive. I'm a big fan.

@MiguelMadero
Copy link
Contributor

Hi @sarus Im glad you got it working. I'm not sure what the difference was with ember. I'm on 1.1.0 beta4 and works great. However, I agree with you, I think it makes sense to use the same version that is documented. However I'll leave the decission to @fivetanley and the contributors of this project to decide.

@fivetanley let me know what do you think. I'm happy to update the PR based as needed.

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

Successfully merging a pull request may close this issue.

3 participants