Use ember-data from drogus fork, easier-overrides branch

This commit is contained in:
Piotr Sarnacki 2013-02-21 02:03:34 +01:00
parent 395c818a64
commit 0a09c96eb1

View File

@ -1,4 +1,4 @@
// Last commit: 8801f2e (2013-02-15 13:53:27 -0800) // Last commit: 6d9eeaf (2013-02-20 22:27:54 +0100)
(function() { (function() {
@ -3918,19 +3918,19 @@ DS.Model.reopen({
attributeDidChange: Ember.observer(function(record, key) { attributeDidChange: Ember.observer(function(record, key) {
record.send('didSetProperty', { name: key }); record.send('didSetProperty', { name: key });
}) }),
});
function getAttr(record, options, key) { getAttr: function(key, options) {
var attributes = get(record, 'data').attributes; var attributes = get(this, 'data').attributes;
var value = attributes[key]; var value = attributes[key];
if (value === undefined) { if (value === undefined) {
value = options.defaultValue; value = options.defaultValue ;
} }
return value; return value;
} }
});
DS.attr = function(type, options) { DS.attr = function(type, options) {
options = options || {}; options = options || {};
@ -3947,7 +3947,7 @@ DS.attr = function(type, options) {
if (arguments.length > 1) { if (arguments.length > 1) {
Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + this.constructor.toString(), key !== 'id'); Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + this.constructor.toString(), key !== 'id');
} else { } else {
value = getAttr(this, options, key); value = this.getAttr(key, options);
} }
return value; return value;
@ -3972,18 +3972,8 @@ DS.attr = function(type, options) {
var get = Ember.get, set = Ember.set, var get = Ember.get, set = Ember.set,
none = Ember.isNone; none = Ember.isNone;
DS.belongsTo = function(type, options) { DS.Model.reopen({
Ember.assert("The first argument DS.belongsTo must be a model type or string, like DS.belongsTo(App.Person)", !!type && (typeof type === 'string' || DS.Model.detect(type))); getBelongsTo: function(key, type, meta) {
options = options || {};
var meta = { type: type, isRelationship: true, options: options, kind: 'belongsTo' };
return Ember.computed(function(key, value) {
if (arguments.length === 2) {
return value === undefined ? null : value;
}
var data = get(this, 'data').belongsTo, var data = get(this, 'data').belongsTo,
store = get(this, 'store'), id; store = get(this, 'store'), id;
@ -4000,6 +3990,22 @@ DS.belongsTo = function(type, options) {
} else { } else {
return store.find(type, id); return store.find(type, id);
} }
}
});
DS.belongsTo = function(type, options) {
Ember.assert("The first argument DS.belongsTo must be a model type or string, like DS.belongsTo(App.Person)", !!type && (typeof type === 'string' || DS.Model.detect(type)));
options = options || {};
var meta = { type: type, isRelationship: true, options: options, kind: 'belongsTo' };
return Ember.computed(function(key, value) {
if (arguments.length === 2) {
return value === undefined ? null : value;
}
return this.getBelongsTo(key, type, meta);
}).property('data').meta(meta); }).property('data').meta(meta);
}; };
@ -4049,12 +4055,8 @@ DS.Model.reopen({
(function() { (function() {
var get = Ember.get, set = Ember.set; var get = Ember.get, set = Ember.set;
var hasRelationship = function(type, options) { DS.Model.reopen({
options = options || {}; getHasMany: function(key, type, meta) {
var meta = { type: type, isRelationship: true, options: options, kind: 'hasMany' };
return Ember.computed(function(key, value) {
var data = get(this, 'data').hasMany, var data = get(this, 'data').hasMany,
store = get(this, 'store'), store = get(this, 'store'),
ids, relationship; ids, relationship;
@ -4069,6 +4071,16 @@ var hasRelationship = function(type, options) {
set(relationship, 'name', key); set(relationship, 'name', key);
return relationship; return relationship;
}
});
var hasRelationship = function(type, options) {
options = options || {};
var meta = { type: type, isRelationship: true, options: options, kind: 'hasMany' };
return Ember.computed(function(key, value) {
return this.getHasMany(key, type, meta);
}).property().meta(meta); }).property().meta(meta);
}; };
@ -4933,7 +4945,9 @@ DS.RelationshipChangeRemove.prototype.sync = function() {
if (secondRecord && firstRecord) { if (secondRecord && firstRecord) {
if(this.secondRecordKind === "belongsTo"){ if(this.secondRecordKind === "belongsTo"){
secondRecord.suspendRelationshipObservers(function(){
set(secondRecord, secondRecordName, null); set(secondRecord, secondRecordName, null);
});
} }
else if(this.secondRecordKind === "hasMany"){ else if(this.secondRecordKind === "hasMany"){
secondRecord.suspendRelationshipObservers(function(){ secondRecord.suspendRelationshipObservers(function(){
@ -6469,7 +6483,6 @@ DS.JSONSerializer = DS.Serializer.extend({
sideloadedType = type.typeForRelationship(prop); sideloadedType = type.typeForRelationship(prop);
console.log('sideloadedType', type, prop, sideloadedType);
if (!sideloadedType) { if (!sideloadedType) {
sideloadedType = this.sideloadMapping.get(prop); sideloadedType = this.sideloadMapping.get(prop);