Skip to content

Commit d28ed91

Browse files
author
Lee Richmond
committed
Make first() return proxy
This was returning the model itself, which does not match the all()/find() APIs. This makes things more consistent.
1 parent 3426ef6 commit d28ed91

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

dist/jsorm.js

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jsorm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class Model {
6464
return this.scope().find(id);
6565
}
6666

67-
static first() : Promise<Model> {
67+
static first() : Promise<RecordProxy<Model>> {
6868
return this.scope().first();
6969
}
7070

src/scope.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ export default class Scope {
3535
});
3636
}
3737

38-
// TODO: paginate 1
39-
first() : Promise<Model> {
40-
return this.per(1).all().then((models : CollectionProxy<Model>) => {
41-
return models.data[0];
38+
first() : Promise<RecordProxy<Model>> {
39+
let newScope = this.per(1);
40+
return newScope._fetch(newScope.model.url()).then((json : japiDoc) => {
41+
json.data = json.data[0];
42+
return new RecordProxy(json);
4243
});
4344
}
4445

test/integration/finders-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Model finders', function() {
7070
});
7171

7272
it('returns a promise that resolves the correct instances', function() {
73-
return expect(Person.first()).to.eventually
73+
return expect(resultData(Person.first())).to.eventually
7474
.be.instanceof(Person)
7575
.have.property('id', '1')
7676
});

0 commit comments

Comments
 (0)