-
Notifications
You must be signed in to change notification settings - Fork 53
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
Upgrade to Ember CLI 0.2.0 and Ember Data 1.0.0-beta.15 #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ export default DS.RESTSerializer.extend({ | |
*/ | ||
extractMeta: function( store, type, payload ) { | ||
if ( payload && payload.count ) { | ||
store.metaForType( type, { count: payload.count } ); | ||
store.setMetadataFor( type, { count: payload.count } ); | ||
delete payload.count; | ||
} | ||
}, | ||
|
@@ -86,9 +86,18 @@ export default DS.RESTSerializer.extend({ | |
// the links property so the adapter can async call the | ||
// relationship. | ||
// The adapter findHasMany has been overridden to make use of this. | ||
if ( options.relation ) { | ||
hash.links = {}; | ||
hash.links[key] = { type: relationship.type, key: key }; | ||
if(options.relation) { | ||
// hash[key] contains the response of Parse.com: eg {__type: Relation, className: MyParseClassName} | ||
// this is an object that make ember-data fail, as it expects nothing or an array ids that represent the records | ||
hash[key] = []; | ||
|
||
// ember-data expects the link to be a string | ||
// The adapter findHasMany will parse it | ||
if (!hash.links) { | ||
hash.links = {}; | ||
} | ||
|
||
hash.links[key] = JSON.stringify({typeKey: relationship.type.typeKey, key: key}); | ||
} | ||
|
||
if ( options.array ) { | ||
|
@@ -121,11 +130,11 @@ export default DS.RESTSerializer.extend({ | |
this._super( type, hash ); | ||
}, | ||
|
||
serializeIntoHash: function( hash, type, record, options ) { | ||
Ember.merge( hash, this.serialize( record, options ) ); | ||
serializeIntoHash: function( hash, type, snapshot, options ) { | ||
Ember.merge( hash, this.serialize( snapshot, options ) ); | ||
}, | ||
|
||
serializeAttribute: function( record, json, key, attribute ) { | ||
serializeAttribute: function( snapshot, json, key, attribute ) { | ||
// These are Parse reserved properties and we won't send them. | ||
if ( 'createdAt' === key || | ||
'updatedAt' === key || | ||
|
@@ -135,29 +144,19 @@ export default DS.RESTSerializer.extend({ | |
delete json[key]; | ||
|
||
} else { | ||
this._super( record, json, key, attribute ); | ||
this._super( snapshot, json, key, attribute ); | ||
} | ||
}, | ||
|
||
serializeBelongsTo: function( record, json, relationship ) { | ||
var key = relationship.key, | ||
belongsTo = record.get( key ); | ||
|
||
if ( belongsTo ) { | ||
// @TODO: Perhaps this is working around a bug in Ember-Data? Why should | ||
// promises be returned here. | ||
if ( belongsTo instanceof DS.PromiseObject ) { | ||
if ( !belongsTo.get('isFulfilled' ) ) { | ||
throw new Error( 'belongsTo values *must* be fulfilled before attempting to serialize them' ); | ||
} | ||
|
||
belongsTo = belongsTo.get( 'content' ); | ||
} | ||
serializeBelongsTo: function( snapshot, json, relationship ) { | ||
var key = relationship.key, | ||
belongsToId = snapshot.belongsTo(key, { id: true }); | ||
|
||
if ( belongsToId ) { | ||
json[key] = { | ||
'__type' : 'Pointer', | ||
'className' : this.parseClassName( belongsTo.constructor.typeKey ), | ||
'objectId' : belongsTo.get( 'id' ) | ||
'className' : this.parseClassName(key), | ||
'objectId' : belongsToId | ||
}; | ||
} | ||
}, | ||
|
@@ -171,10 +170,11 @@ export default DS.RESTSerializer.extend({ | |
} | ||
}, | ||
|
||
serializeHasMany: function( record, json, relationship ) { | ||
var key = relationship.key, | ||
hasMany = record.get( key ), | ||
options = relationship.options; | ||
serializeHasMany: function( snapshot, json, relationship ) { | ||
var key = relationship.key, | ||
hasMany = snapshot.hasMany( key ), | ||
options = relationship.options, | ||
_this = this; | ||
|
||
if ( hasMany && hasMany.get( 'length' ) > 0 ) { | ||
json[key] = { 'objects': [] }; | ||
|
@@ -190,8 +190,8 @@ export default DS.RESTSerializer.extend({ | |
hasMany.forEach( function( child ) { | ||
json[key].objects.push({ | ||
'__type' : 'Pointer', | ||
'className' : child.parseClassName(), | ||
'objectId' : child.get( 'id' ) | ||
'className' : _this.parseClassName(child.type.typeKey), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In IMO only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something hopefully @joshfester or @Kira2 can speak to. I'm honestly just going through the commits at github.com/joshfester/ember-parse-adapter and extracting the ones that are applicable to Ember Data 1.0.0-beta.15 and replaying them onto the Ember CLI Add-on version of the adapter. I will then do the same thing with other commits against Ember Data 1.0.0-beta.16 and again with other generic fixes, etc. I have not been focusing on the specific changes that were applied or why - if the tests are passing and the demo app still functions I have viewed it as being functionally correct. I am trying to facilitate the convergence of several different development efforts into this single repository in the Ember CLI format. At that point I, and others, can begin focusing specifically on refactors and improvements. If there is a different approach you would rather I and others to follow I am open to suggestions - I am just trying to move progress forward. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
'objectId' : child.attr( 'id' ) | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeKey
as the key? Nottype
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
joshfester@121909d introduced the JSON.stringify() call and joshfester@337d2ff changed "type" to "typeKey"
I mean to include the commit messages from each of these hashes into this commit listed under each referenced hash. If this is preferred I can cancel this pull request and re-commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes were from a pull request by @Kira2 so hopefully we can get her involved. Without running any tests I'm not sure of the difference between typeKey and type. @mixonic could you elaborate on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeKey
is an Ember-Data internal string version of the model name. Creating a payload for push that looks like:Would not actually set the
typeKey
. Instead polymorphic payload are intended to pass their type in a payload astype
:In short, pushing
typeKey:
into the store doesn't so anything afaik.