-
Notifications
You must be signed in to change notification settings - Fork 19
added type parameter to the relations #36
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
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 |
|---|---|---|
|
|
@@ -388,12 +388,12 @@ const RelatedProxyUtil = Ember.Object.extend({ | |
| @param {Ember.ObjectProxy|Ember.ArrayProxy} proxyFactory | ||
| @return {PromiseProxy} proxy | ||
| */ | ||
| createProxy: function (resource, proxyFactory) { | ||
| createProxy: function (resource, type, proxyFactory) { | ||
| const relation = this.get('relationship'); | ||
| const url = this.proxyUrl(resource, relation); | ||
| const service = resource.container.lookup('service:' + pluralize(relation)); | ||
| const service = resource.container.lookup('service:' + pluralize(type)); | ||
| let promise = this.promiseFromCache(resource, relation, service); | ||
| promise = promise || service.findRelated(relation, url); | ||
| promise = promise || service.findRelated(type, url); | ||
| let proxy = proxyFactory.extend(Ember.PromiseProxyMixin, { | ||
| 'promise': promise, 'type': relation | ||
|
Owner
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. I'm curious if
Author
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. From what I can tell, the type parameter on line 398 is not used at the moment, but I am probably missing something here... |
||
| }); | ||
|
|
@@ -472,18 +472,24 @@ function linksPath(relation) { | |
| } | ||
|
|
||
| /** | ||
| Helper to setup a has one relationship to another resource | ||
| Helper to setup a has one relationship to another resource, | ||
| type is optional and defaults to relation | ||
|
|
||
| @method hasOne | ||
| @param {String} relation | ||
| @param {Object|String} relation | ||
| */ | ||
| export function hasOne(relation) { | ||
| assertDasherizedHasOneRelation(relation); | ||
| const util = RelatedProxyUtil.create({'relationship': relation}); | ||
| const path = linksPath(relation); | ||
| let relationName = relation; | ||
| if (typeof relation !== 'string') { | ||
| relationName = relation.resource; | ||
| } | ||
| const util = RelatedProxyUtil.create({'relationship': relationName}); | ||
| const path = linksPath(relationName); | ||
| assertDasherizedHasOneRelation(relationName); | ||
| const type = (relation.type ? relation.type : relationName); | ||
| return Ember.computed(path, function () { | ||
| return util.createProxy(this, Ember.ObjectProxy); | ||
| }).meta({relation: relation, kind: 'hasOne'}); | ||
| return util.createProxy(this, type, Ember.ObjectProxy); | ||
| }).meta({relation: relationName, type: type, kind: 'hasOne'}); | ||
| } | ||
|
|
||
| function assertDasherizedHasOneRelation(name) { | ||
|
|
@@ -498,18 +504,24 @@ function assertDasherizedHasOneRelation(name) { | |
| } | ||
|
|
||
| /** | ||
| Helper to setup a has many relationship to another resource | ||
| Helper to setup a has many relationship to another resource, | ||
| type is optional and defaults to relation | ||
|
|
||
| @method hasMany | ||
| @param {String} relation | ||
| @param {String|Object} relation | ||
| */ | ||
| export function hasMany(relation) { | ||
| assertDasherizedHasManyRelation(relation); | ||
| const util = RelatedProxyUtil.create({'relationship': relation}); | ||
| const path = linksPath(relation); | ||
| let relationName = relation; | ||
| if (typeof relation !== 'string') { | ||
| relationName = relation.resource; | ||
| } | ||
| const util = RelatedProxyUtil.create({'relationship': relationName}); | ||
| const path = linksPath(relationName); | ||
| assertDasherizedHasManyRelation(relationName); | ||
| const type = (relation.type ? relation.type : relationName); | ||
| return Ember.computed(path, function () { | ||
| return util.createProxy(this, Ember.ArrayProxy); | ||
| }).meta({relation: relation, kind: 'hasMany'}); | ||
| return util.createProxy(this, type, Ember.ArrayProxy); | ||
| }).meta({relation: relationName, type: type, kind: 'hasMany'}); | ||
| } | ||
|
|
||
| function assertDasherizedHasManyRelation(name) { | ||
|
|
||
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.
The API returned a URL for the relation which is still used for the
urlwhen callingservice.findRelated; however, it seems that the service you want to use should be configurable based on either the (default)resourcename or an optionaltypenameThere 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.
I think this is already the case: the type defines the service to use in line
Resource defines the url to use:
So the
urlis created based on thethis.get('relationship'), which gets the value ofresource.The
typeis passed in and is either passed to the relation (e.g.hasOne) in a hash or takes the same value asresource...
The only problem I have now is that I probably should have passed the type like the relationship is passed: in the create, not as a parameter
would become
and would probably be more clear...