Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions addon/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ export default Ember.Object.extend(FetchMixin, Evented, {
service.findRelated('photographer', '/api/v1/photos/1/relationships/photographer');
```

Or, with option to find releated resource using a different service
Or, with option to find related resource using a different service

```js
service.findRelated({resource: 'photographer', type: 'people'}, url);
service.findRelated({relation: 'photographer', type: 'people'}, url);
```

@method findRelated
@param {String|Object} resource name to lookup the service object w/ serializer
@param {String} resource.resource the name of the resource
@param {String|Object} relation name to lookup the service object w/ serializer
@param {String} relation.relation the name of the relationship
@param {String} resource.type the name of the resource
@param {String} url
@return {Promise}
*/
findRelated(resource, url) {
let type = resource;
findRelated(relation, url) {
let type = relation;
if (typeof type === 'object') {
type = resource.type;
type = relation.type;
}
// use resource's service if in container, otherwise use this service to fetch
let service = getOwner(this).lookup('service:' + pluralize(type)) || this;
Expand Down
2 changes: 1 addition & 1 deletion addon/utils/related-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const RelatedProxyUtil = Ember.Object.extend({
let owner = Ember.getOwner(resource);
let service = owner.lookup('service:' + pluralize(type));
let promise = this.promiseFromCache(resource, relation, service);
promise = promise || service.findRelated({'resource': relation, 'type': type}, url);
promise = promise || service.findRelated({'relation': relation, 'type': type}, url);
let proxyProto = proxyFactory.extend(Ember.PromiseProxyMixin, {
'promise': promise, 'type': relation, 'kind': kind
});
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/adapters/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ test('#findRelated', function(assert) {
});
});

test('#findRelated is called with optional type for the resource', function (assert) {
test('#findRelated is called with optional type for the relation', function (assert) {
assert.expect(4);
const done = assert.async();

Expand All @@ -295,7 +295,7 @@ test('#findRelated is called with optional type for the resource', function (ass
let url = supervisor.get('relationships.direct-reports.links.related');
supervisor.get('directReports').then(() => {
assert.ok(stub.calledOnce, 'employees service findRelated method called once');
assert.equal(stub.firstCall.args[0].resource, 'direct-reports', 'findRelated called with "direct-reports" resource');
assert.equal(stub.firstCall.args[0].relation, 'direct-reports', 'findRelated called with "direct-reports" relation');
assert.equal(stub.firstCall.args[0].type, 'employees', 'findRelated called with employees type');
assert.equal(stub.firstCall.args[1], url, 'findRelated called with url, ' + url);
done();
Expand Down