@@ -380,6 +380,15 @@ const RelatedProxyUtil = Ember.Object.extend({
380380 */
381381 relationship : null ,
382382
383+ /**
384+ The name of the type of resource
385+
386+ @property type
387+ @type String
388+ @required
389+ */
390+ type : null ,
391+
383392 /**
384393 Proxy for the requested relation, resolves w/ content from fulfilled promise
385394
@@ -389,11 +398,12 @@ const RelatedProxyUtil = Ember.Object.extend({
389398 @return {PromiseProxy } proxy
390399 */
391400 createProxy : function ( resource , proxyFactory ) {
392- const relation = this . get ( 'relationship' ) ;
393- const url = this . proxyUrl ( resource , relation ) ;
394- const service = resource . container . lookup ( 'service:' + pluralize ( relation ) ) ;
401+ let relation = this . get ( 'relationship' ) ;
402+ let type = this . get ( 'type' ) ;
403+ let url = this . proxyUrl ( resource , relation ) ;
404+ let service = resource . container . lookup ( 'service:' + pluralize ( type ) ) ;
395405 let promise = this . promiseFromCache ( resource , relation , service ) ;
396- promise = promise || service . findRelated ( relation , url ) ;
406+ promise = promise || service . findRelated ( { 'resource' : relation , 'type' : type } , url ) ;
397407 let proxy = proxyFactory . extend ( Ember . PromiseProxyMixin , {
398408 'promise' : promise , 'type' : relation
399409 } ) ;
@@ -476,14 +486,30 @@ function linksPath(relation) {
476486
477487 @method hasOne
478488 @param {String } relation
489+ Or, {Object} with properties for `resource` and `type`
479490*/
480491export function hasOne ( relation ) {
481- assertDasherizedHasOneRelation ( relation ) ;
482- const util = RelatedProxyUtil . create ( { 'relationship' : relation } ) ;
483- const path = linksPath ( relation ) ;
492+ let type = relation ;
493+ if ( typeof type === 'object' ) {
494+ assertResourceAndTypeProps ( relation ) ;
495+ type = relation . type ;
496+ relation = relation . resource ;
497+ }
498+ assertDasherizedHasOneRelation ( type ) ;
499+ let util = RelatedProxyUtil . create ( { 'relationship' : relation , 'type' : type } ) ;
500+ let path = linksPath ( relation ) ;
484501 return Ember . computed ( path , function ( ) {
485502 return util . createProxy ( this , Ember . ObjectProxy ) ;
486- } ) . meta ( { relation : relation , kind : 'hasOne' } ) ;
503+ } ) . meta ( { relation : relation , type : type , kind : 'hasOne' } ) ;
504+ }
505+
506+ function assertResourceAndTypeProps ( relation ) {
507+ try {
508+ let msg = 'Options must include properties: resource, type' ;
509+ Ember . assert ( msg , relation && relation . resource && relation . type ) ;
510+ } catch ( e ) {
511+ console . warn ( e . message ) ;
512+ }
487513}
488514
489515function assertDasherizedHasOneRelation ( name ) {
@@ -502,14 +528,21 @@ function assertDasherizedHasOneRelation(name) {
502528
503529 @method hasMany
504530 @param {String } relation
531+ Or, {Object} with properties for `resource` and `type`
505532*/
506533export function hasMany ( relation ) {
534+ let type = relation ;
535+ if ( typeof type === 'object' ) {
536+ assertResourceAndTypeProps ( relation ) ;
537+ type = relation . type ;
538+ relation = relation . resource ;
539+ }
507540 assertDasherizedHasManyRelation ( relation ) ;
508- const util = RelatedProxyUtil . create ( { 'relationship' : relation } ) ;
509- const path = linksPath ( relation ) ;
541+ let util = RelatedProxyUtil . create ( { 'relationship' : relation , 'type' : type } ) ;
542+ let path = linksPath ( relation ) ;
510543 return Ember . computed ( path , function ( ) {
511544 return util . createProxy ( this , Ember . ArrayProxy ) ;
512- } ) . meta ( { relation : relation , kind : 'hasMany' } ) ;
545+ } ) . meta ( { relation : relation , type : type , kind : 'hasMany' } ) ;
513546}
514547
515548function assertDasherizedHasManyRelation ( name ) {
0 commit comments