Giter VIP home page Giter VIP logo

ember-model's Issues

RecordArray#reload()

Since we always return the same RecordArray from findAll, we should add a method on the RecordArray to force an update

Force object reload after save()

Im saving a record to the server that has multiple joins. How can I force the record to reload from the server after the save or can I return the updated json and replace the records current state?

something along these lines

  question.save().then(function() {
    question.reload();
    question.set('isEditing', false);
  });

or

  question.save().then(function(data) {
    // ... update the state of the record
    question.set('isEditing', false);
  });

FixtureAdapter#findMany returns a RecordArray full of nulls

Hi Erik,

Considering this Employee Model. I am using the REST Adapter to load an Employee from the server.

App.Employee = Ember.Model.extend({
  firstName: Ember.attr('string'),
  lastName: Ember.attr('string'),
  email: Ember.attr('string'),
  phoneNumbers: function() {
      return App.PhoneNumber.find('1323 1262'.w());
  }.property()
});

Everything is fine until I use phoneNumbers in my template with the each helper.

{{#each phoneNumber in phoneNumbers}}
  {{phoneNumber.id}}
{{/each}}

I am getting the error: You must pass at least an object and event name to Ember.addListener. I think, the reason is that at first phoneNumbers.length === 2 but both values are nulls.

Everything is working as expected, if I comment out Ember.RecordArray.length CP.

Thanks

ember-model and new async route in ember RC6

Hi,

I'm not sure if it's an ember-model problem, sorry if it's not.
I updated to ember RC6 using ember-data and everything was OK, after migrating to ember-model one of my transitions stopped working. I narrowed down to this line:

return this.modelFor("product.images").get('images');

It seems it can't "resolve" that array and so it never makes the transition.

Everything else works:

return Ember.A([{id: 1, link: "product_1_1.jpg"}, {id: 2, link: "product_1_2.jpg"}]);

and

return App.ProductImages.find([1,2]);

My imagesis configured as follow:

images: Ember.hasMany('App.ProductImage', 'images'),

Push support

Kinda related to #4. We want to be able to partially create models with data received from push notifications and have them trigger a find to retrieve their full content.

Changing namespace of the libray to something else than Ember

The namespacing of Ember Model is Ember for all of the classes. This is fine as long as it does not conflicts with any Ember's methods or objects nor with any other libraries. I think that this is a good moment to discuss possible change. The library hasn't got too big user base yet, so impact will not be huge - I think that later on such thing will simply not be possible. Old names could be left as references so the library can continue working without changing the apps for some time.

Document error handling

Our belief is that error handling should be done inside controllers off the returned promises.

`belongsTo` does not load model when accessed directly from nested URL resource

I've created the following JSBin that shows the issue,

http://jsbin.com/etazij/1/edit

When I access the parent ("tables") resource first by going to,

http://jsbin.com/etazij/1#/tables

and then clicking on any numbers (1 - 6), Ember Model loads the "Tab" model correctly for the "Table".

However, if I were to access the "table" resource from the URL by going to the following links directly from the browser,

http://jsbin.com/etazij/1#/tables/1
http://jsbin.com/etazij/1#/tables/2
http://jsbin.com/etazij/1#/tables/3
http://jsbin.com/etazij/1#/tables/4
http://jsbin.com/etazij/1#/tables/5
http://jsbin.com/etazij/1#/tables/6

"Tab" model fails to load for that specific "Table".

Please let me know if you need more information. Thank you!

Calling create in async route causes white screen of death

I'm likely doing something wrong, but I think this has something to do with the new async router stuff in rc6. This works:

App.DashboardsNewRoute = Em.Route.extend
    setupController: (controller) -> 
        dashboard = App.Dashboard.create()
        controller.set 'model', dashboard

But this does not:

App.DashboardsNewRoute = Em.Route.extend
    model: () -> 
        App.Dashboard.create()

I tried stepping through the router, but there doesn't seem to be anything wrong going on. Does create return a promise? Looking at the code it doesn't seem like it does anything special in init.

Any ideas?

findMany([1]) doesn't work

Using findMany will batch the requested ids, which however has a different logic if the batch only contains one id, which results in the following issue

http://i.imgur.com/PZvrVAs.png

The problem seems to be here, I wasn't able to write a failing test for this though, but it can be simply reproduced by doing find([1]) or findMany([1])

toJSON support for Array attributes

Currently when saving a model with an EmberArray attribute, the attribute is not sent as a proper JSON array.

Example:
model.coffee

artist_ids: attr()

controller.coffee

artists = @get('model.artist_ids')
artists.push('1234')
@get('model').set('artist_ids', artists)
@get('model').save()

results in this request param:
"artist_ids"=>{"0"=>"1234", "length"=>1}
when we would expect:
"artist_ids"=>["1234"]

If we use a newly created array, the params are correct:
controller.coffee

artists = []
artists.push(artist_id) for artist_id in @get('model.artist_ids')
artists.push('1234')
@get('model').set('artist_ids', artists)
@get('model').save()

results in this request param:
"artist_ids"=>["1234"]

Model#update

Would be nice to have a way to force a model to fetch updated data from the server

Trouble running tests with new build process

Hi,

This is most likely a configuration issue on my side, but if I do a clean clone of ember-model I'm unable to run the tests. After npm install / bower install / grunt test I get the following output:

Running "qunit:cli" (qunit) task
Testing tests/index.html Fatal error: spawn EACCES

I read up that EACCES refers to Node not having the correct privileges to access the file system so as a temporary hack, I ran:

 chmod -R 777 *

I know this is not best practice but just wanted to remove possible permissions issue. I now run into the following issue but I'm not quite sure how to fix it:

Running "qunit:cli" (qunit) task
Testing tests/index.html 
Warning: PhantomJS timed out, possibly due to a missing QUnit start() call. Used -- force, continuing.
Warning: 0/0 assertions ran (0ms) Used --force, continuing.

I'm not sure if there is something funny with my system Node.js config or if its the test configuration.

I have re-installed npm and node to the latest version v0.10.2

Proper sideloading with embedded objects

Im trying to understand the proper way to sideload embedded objects. I started to use the hasMany but I believe that at the moment its still being tweaked.

In the meantime im trying to use a computed property. I just dont think im doing it correctly.

I put together a more detailed description on Stack any advise would be great

http://stackoverflow.com/q/17462341/1408461

Add ability to rollback changes to a model object

Maybe I'm missing it, but is there a canonical way to cancel changes to a model object if the user navigates away without submitting?

Ember Data has the concept of transactions and rollback. Is there something similar in Ember Model?

ember-model and its dependencies (grunt)

Hi,

I'm trying to use ember-model and grunt in windows 7 64bits. But npm install complains that I don't have python, installing python it complains that I don't have Visual Studio. WTF? I'm downloading it right now, but will I have to download 400+MB of things to just build ember-model in Windows?

The package that requires that is execSync, that requires fii, that requires node-gyp that blows everything.

Server-generated data should be communicable to the client

When persisting an object, part of which is generated on the server, the server-side-generated data doesn't seem to be able to be conveyed back to the browser. I can return the entire object with its generated data in the response, but there doesn't appear to be a way to get that to feed back into the Ember model.

For example, when someone fills out a Report, the current user needs to be listed as the author of the report and tags are generated based on keywords contained in the body. If this is all done on the server side, we need a way to let the client know what that data is. Otherwise, we'll have to duplicate that logic on the client and/or just do it in the client and trust that the client isn't lying to us.

RESTAdapter#find requires Record.rootKey but does not use it

  find: function(record, id) {
    var url = this.buildURL(record.constructor, id),
        rootKey = record.constructor.rootKey;

    if (!rootKey) {
      throw new Error('Ember.RESTAdapter requires a `rootKey` property to be specified');
    }

    return this.ajax(url).then(function(data) {
      Ember.run(record, record.load, id, data);
    });
  }

I expected to see the following, or something equivalent. (or maybe not requiring rootKey, but if present, using it in this manner)

Ember.run(record, record.load, id, data[rootKey]);

RESTAdapter#createRecord isn't nesting the payload

I'm not sure if this is intentionally ommited, since ember-model is aiming to provide a lot more flexibility than ember-data, but the behavior is different.

App.User.create({ name: "foo" }).save()
// POST /users.json { name: "foo" }

while the convention is to do POST /users.json { name: "foo" }. Would a PR to change this be accepted? Or not change, but maybe add an extension point to the RESTAdapter so that it is easy to override how the outcoming JSON is handled?

Here's an example (from the brains of @mekishizufu)

  createRecord: function(record) {
    var url = this.buildURL(record.constructor);

    return this.ajax(url, this.paramsFor(record), "POST").then(function(data) {
      Ember.run(function() {
        record.load(data.id, data);
        record.didCreateRecord();
      });
    });
  },

  paramsFor: function(record) {
    var rootKey = get(record.constructor, "rootKey"), json = record.toJSON(),
      params = {};

    if (rootKey) {
      params[rootKey] = json;
    } else {
      params = json;
    }

    return params;
  },

where paramsFor could just return record.toJSON() by default, but would be easier to override. Right now you basically need to override every adapter method to change this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.