Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
88f908a
Fixing bug where hasMany could not get classname in some cases. close…
igorsantos07 Apr 27, 2015
5d04e4f
Merge pull request #1 from clintjhill/master
igorsantos07 May 17, 2015
0fdd8c4
Upgrading computed properties for new syntax on Ember 0.12 (fixes dep…
igorsantos07 May 17, 2015
c11a645
Fixing id getter on hasMany serialization
igorsantos07 Jun 1, 2015
9439137
Merge branch 'patch-1'
igorsantos07 Jun 7, 2015
023899a
Merge branch 'patch-2'
igorsantos07 Jun 7, 2015
b15b7c6
Fixing some code-styling issues and huge issue on custom-named belong…
igorsantos07 Jun 7, 2015
0e5d29f
Using new CP syntax with ES5 getter/setter syntax, as babel does not …
igorsantos07 Jun 9, 2015
138f7fe
updated ember-cli to 1.13.8
joshfester Aug 10, 2015
2d1283a
updated to ember 1.13.7
joshfester Aug 10, 2015
c1ec9f6
brocfile deprecation
joshfester Aug 10, 2015
0807f78
updated all dependencies except ember data
joshfester Aug 10, 2015
43990ce
updated content security policy for dummy app
joshfester Aug 10, 2015
f8c2484
whoops didn't finish the content security policy
joshfester Aug 10, 2015
1afda46
a new record with no hasmany relationships yet should send nothing in…
joshfester Aug 10, 2015
c6aec48
dummy app needs to save tiger after adding a stripe
joshfester Aug 10, 2015
8e21e83
Merge commit 'refs/pull/73/head' of https://github.com/clintjhill/emb…
joshfester Aug 10, 2015
3823422
update computed property for sessionToken. update test to expect null…
joshfester Aug 10, 2015
dbac273
hasmany relationships now work
joshfester Aug 10, 2015
de16194
updated to ember data 1.0.0-beta.16
joshfester Aug 11, 2015
a191d64
updated to ember data 1.0.0-beta.18
joshfester Aug 11, 2015
332c6a7
initial changes for update to ember data 1.0.0-beta.19
joshfester Aug 11, 2015
eb99a8d
working and passing tests
joshfester Aug 11, 2015
bfce122
keep forgetting to remove my personal tests in the dummy app
joshfester Aug 11, 2015
6b28a04
change relationship.type.typeKey to relationship.type in normalizeRel…
joshfester Aug 11, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["tmp"]
}
21 changes: 0 additions & 21 deletions Brocfile.js

This file was deleted.

33 changes: 17 additions & 16 deletions addon/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default DS.RESTAdapter.extend({
classesPath: 'classes',

pathForType: function( type ) {
if ( 'parseUser' === type ) {
if ( 'parseUser' === type || 'parse-user' === type ) {
return 'users';
} else if ( 'login' === type ) {
return 'login';
Expand All @@ -42,9 +42,8 @@ export default DS.RESTAdapter.extend({
* properties onto existing data so that the record maintains
* latest data.
*/
createRecord: function( store, type, record ) {
createRecord: function( store, type, snapshot ) {
var serializer = store.serializerFor( type.typeKey ),
snapshot = record._createSnapshot(),
data = {},
adapter = this;

Expand All @@ -69,10 +68,9 @@ export default DS.RESTAdapter.extend({
* properties onto existing data so that the record maintains
* latest data.
*/
updateRecord: function(store, type, record) {
updateRecord: function(store, type, snapshot) {
var serializer = store.serializerFor( type.typeKey ),
snapshot = record._createSnapshot(),
id = record.get( 'id' ),
id = snapshot.id,
sendDeletes = false,
deleteds = {},
data = {},
Expand Down Expand Up @@ -129,24 +127,26 @@ export default DS.RESTAdapter.extend({
* Implementation of a hasMany that provides a Relation query for Parse
* objects.
*/
findHasMany: function( store, record, relatedInfo ) {
var relatedInfo_ = JSON.parse( relatedInfo ),
findHasMany: function( store, snapshot, url, relationship ) {
var relatedInfo_ = JSON.parse( url ),
query = {
where: {
'$relatedTo': {
'object': {
'__type' : 'Pointer',
'className' : this.parseClassName( record.typeKey ),
'objectId' : record.get( 'id' )
'className' : this.parseClassName( snapshot.typeKey ),
'objectId' : snapshot.id
},
key: relatedInfo_.key
}
}
};



// the request is to the related type and not the type for the record.
// the query is where there is a pointer to this record.
return this.ajax( this.buildURL( relatedInfo_.typeKey ), "GET", { data: query } );
return this.ajax( this.buildURL( relationship.type ), "GET", { data: query } );
},

/**
Expand All @@ -173,11 +173,12 @@ export default DS.RESTAdapter.extend({
return this._super( store, type, query );
},

sessionToken: Ember.computed( 'headers.X-Parse-Session-Token', function( key, value ) {
if ( arguments.length < 2 ) {
return this.get( 'headers.X-Parse-Session-Token' );
} else {
this.set( 'headers.X-Parse-Session-Token', value );
sessionToken: Ember.computed('headers.X-Parse-Session-Token', {
get: function get() {
return this.get('headers.X-Parse-Session-Token');
},
set: function set(key, value) {
this.set('headers.X-Parse-Session-Token', value);
return value;
}
})
Expand Down
14 changes: 7 additions & 7 deletions addon/models/parse-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var ParseUser = DS.Model.extend({

ParseUser.reopenClass({
requestPasswordReset: function( email ) {
var adapter = this.get( 'store' ).adapterFor( this ),
var adapter = this.get( 'store' ).adapterFor( 'parse-user' ),
data = { email: email };

return adapter.ajax( adapter.buildURL( 'requestPasswordReset' ), 'POST', { data:data } )['catch'] (
Expand All @@ -30,8 +30,8 @@ ParseUser.reopenClass({

login: function( store, data ) {
var model = this,
adapter = store.adapterFor( model ),
serializer = store.serializerFor( model );
adapter = store.adapterFor( 'parse-user' ),
serializer = store.serializerFor( 'parse-user' );

if ( Ember.isEmpty( this.typeKey ) ) {
throw new Error( 'Parse login must be called on a model fetched via store.modelFor' );
Expand All @@ -40,7 +40,7 @@ ParseUser.reopenClass({
return adapter.ajax( adapter.buildURL( 'login' ), 'GET', { data: data } ).then(
function( response ) {
serializer.normalize( model, response );
var record = store.push( model, response );
var record = store.push( 'parse-user', response );
return record;
},
function( response ) {
Expand All @@ -51,8 +51,8 @@ ParseUser.reopenClass({

signup: function( store, data ) {
var model = this,
adapter = store.adapterFor(model),
serializer = store.serializerFor(model);
adapter = store.adapterFor('parse-user'),
serializer = store.serializerFor('parse-user');

if ( Ember.isEmpty( this.typeKey ) ) {
throw new Error( 'Parse signup must be called on a model fetched via store.modelFor' );
Expand All @@ -63,7 +63,7 @@ ParseUser.reopenClass({
serializer.normalize( model, response );
response.email = response.email || data.email;
response.username = response.username || data.username;
var record = store.push( model, response );
var record = store.push( 'parse-user', response );
return record;
},
function( response ) {
Expand Down
35 changes: 19 additions & 16 deletions addon/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default DS.RESTSerializer.extend({
return this._super( store, primaryType, namespacedPayload, recordId );
},

typeForRoot: function( key ) {
modelNameFromPayloadKey: function( key ) {
return Ember.String.dasherize( Ember.String.singularize( key ) );
},

Expand Down Expand Up @@ -86,7 +86,7 @@ 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) {
//if(options.relation) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recall what was happening here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release notes said that the typeForRoot function had been changed to modelNameFromPayloadKey

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant options.relationship vs options.array. I recall now, they are two different options for how to persist a relationship. One with an array of ids, one with w URL.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my bad. See my comment below about that. Not sure what should be happening with those two options.

// 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] = [];
Expand All @@ -97,8 +97,8 @@ export default DS.RESTSerializer.extend({
hash.links = {};
}

hash.links[key] = JSON.stringify({typeKey: relationship.type.typeKey, key: key});
}
hash.links[key] = JSON.stringify({typeKey: relationship.type, key: key});
//}

if ( options.array ) {
// Parse will return [null] for empty relationships
Expand Down Expand Up @@ -148,25 +148,24 @@ export default DS.RESTSerializer.extend({
}
},

serializeBelongsTo: function( snapshot, json, relationship ) {
serializeBelongsTo: function(snapshot, json, relationship) {
var key = relationship.key,
belongsToId = snapshot.belongsTo(key, { id: true });

if ( belongsToId ) {
if (belongsToId) {
json[key] = {
'__type' : 'Pointer',
'className' : this.parseClassName(key),
'className' : this.parseClassName(relationship.type),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above type.typeKey is referenced. type is correct here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that needs to be updated. type is correct

'objectId' : belongsToId
};
}
},

parseClassName: function( key ) {
if ( 'parseUser' === key) {
parseClassName: function(key) {
if ('parseUser' === key) {
return '_User';

} else {
return Ember.String.capitalize( Ember.String.camelize( key ) );
return Ember.String.capitalize(Ember.String.camelize(key));
}
},

Expand All @@ -179,19 +178,23 @@ export default DS.RESTSerializer.extend({
if ( hasMany && hasMany.get( 'length' ) > 0 ) {
json[key] = { 'objects': [] };

if ( options.relation ) {
// an array is not a relationship, right?

/*if ( options.relation ) {
json[key].__op = 'AddRelation';
}

if ( options.array ) {
json[key].__op = 'AddUnique';
}
}*/

json[key].__op = 'AddRelation';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the array style still supported and tested?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where options.relation and options.array should be coming from. Those properties are undefined in the current master branch


hasMany.forEach( function( child ) {
json[key].objects.push({
'__type' : 'Pointer',
'className' : _this.parseClassName(child.type.typeKey),
'objectId' : child.attr( 'id' )
'objectId' : child.id
});
});

Expand Down Expand Up @@ -225,8 +228,8 @@ export default DS.RESTSerializer.extend({
}

} else {
json[key] = [];
json[key] = null;
}
}

});
});
16 changes: 8 additions & 8 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "ember-parse-adapter",
"dependencies": {
"jquery": "^1.11.1",
"ember": "1.10.0",
"ember-data": "1.0.0-beta.15",
"ember-resolver": "~0.1.12",
"loader.js": "ember-cli/loader.js#3.2.0",
"ember": "1.13.7",
"ember-data": "1.0.0-beta.19",
"ember-resolver": "~0.1.15",
"loader.js": "ember-cli/loader.js#3.3.0",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2",
"ember-qunit": "0.2.8",
"ember-cli-test-loader": "ember-cli-test-loader#0.2.0",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.5",
"ember-qunit": "0.4.9",
"ember-qunit-notifications": "0.0.7",
"qunit": "~1.17.1"
"qunit": "~1.18.0"
}
}
35 changes: 35 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
scenarios: [
{
name: 'default',
dependencies: { }
},
{
name: 'ember-release',
dependencies: {
'ember': 'components/ember#release'
},
resolutions: {
'ember': 'release'
}
},
{
name: 'ember-beta',
dependencies: {
'ember': 'components/ember#beta'
},
resolutions: {
'ember': 'beta'
}
},
{
name: 'ember-canary',
dependencies: {
'ember': 'components/ember#canary'
},
resolutions: {
'ember': 'canary'
}
}
]
};
17 changes: 17 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
var app = new EmberApp(defaults, {
// Add options here
});

/*
This build file specifes the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
};
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.0",
"ember-cli": "0.2.7",
"ember-cli": "1.13.8",
"ember-cli-app-version": "0.3.2",
"ember-cli-babel": "^4.0.0",
"ember-cli-content-security-policy": "0.3.0",
"ember-cli-dependency-checker": "0.0.8",
"ember-cli-htmlbars": "0.7.4",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.9",
"ember-cli-babel": "5.1.3",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "1.0.1",
"ember-cli-htmlbars": "0.7.9",
"ember-cli-ic-ajax": "0.2.1",
"ember-cli-inject-live-reload": "1.3.1",
"ember-cli-qunit": "1.0.0",
"ember-cli-uglify": "1.0.1",
"ember-data": "1.0.0-beta.15",
"ember-export-application-global": "^1.0.2"
"ember-data": "1.0.0-beta.19",
"ember-export-application-global": "1.0.3"
},
"keywords": [
"ember-addon",
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/controllers/hasmany.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export default Ember.Controller.extend({
var tiger = this.get( 'model' ),
stripe = tiger.get( 'stripes' ).createRecord();

stripe.save().then( function( tiger ) {
stripe.save().then( function( stripe ) {
tiger.save();
});
}

}
});
2 changes: 1 addition & 1 deletion tests/dummy/app/models/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
tiger: DS.belongsTo( 'tiger' )
tiger: DS.belongsTo( 'tiger', { async: true } )
});
2 changes: 1 addition & 1 deletion tests/dummy/app/models/tiger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr( 'string' ),
stripes: DS.hasMany( 'stripe' )
stripes: DS.hasMany( 'stripe', { async: true } )
});
Loading