ebryn / ember-model Goto Github PK
View Code? Open in Web Editor NEWA lightweight model library for Ember.js
License: MIT License
A lightweight model library for Ember.js
License: MIT License
See the (breaking) test in this commit for more details.
Since we always return the same RecordArray from findAll, we should add a method on the RecordArray to force an update
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);
});
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
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 images
is configured as follow:
images: Ember.hasMany('App.ProductImage', 'images'),
Just landed hasMany and belongsTo from #90
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.
Let me know if an ember-model source hosting URL already exists. If it doesn't, I would like to know how to include it in my ember app so I can use it. Thanks.
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.
Our belief is that error handling should be done inside controllers off the returned promises.
isFullyLoaded flag probably
hasMany, belongsTo, etc
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!
The error messages should include the class name, so it's easier to see where the error is coming from.
https://github.com/ebryn/ember-model/blob/master/packages/ember-model/lib/adapter.js#L3
Add tests, etc
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 is defined in the Adapter base class, which causes this condition to be true. Workaround is to define findMany: null
in your subclass.
https://github.com/ebryn/ember-model/blob/master/packages/ember-model/lib/model.js#L405
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
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])
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"]
Would be nice to have a way to force a model to fetch updated data from the server
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
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
Upon creation or save?
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?
When the type
of a hasMany relationship doesn't have an adapter set an error should be getting thrown here, but it's getting eaten by a promise:
https://github.com/ebryn/ember-model/blob/master/packages/ember-model/lib/has_many_array.js#L48
Looking at you @realityendshere. Help us out :)
The plan is to provide the typical belongsTo
and hasMany
helpers, but for now you can easily roll them yourself with computed properties.
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.
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.
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]);
There isn't a way to know if every record in a ManyArray has been loaded.
Causes issues with dirty tracking
https://github.com/ebryn/ember-model/blob/master/packages/ember-model/lib/has_many.js#L11
This will help people catch their mistakes.
Title says it all :)
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.