diff --git a/src/Orm/Relations/AggregatesLoader/LazyLoad.ts b/src/Orm/Relations/AggregatesLoader/LazyLoad.ts index dee5e508..01901e0a 100644 --- a/src/Orm/Relations/AggregatesLoader/LazyLoad.ts +++ b/src/Orm/Relations/AggregatesLoader/LazyLoad.ts @@ -59,7 +59,7 @@ export class LazyLoadAggregates * Execute query */ public async exec() { - const result = await this.query.first() + const result = await this.query.pojo().first() if (!result) { return } diff --git a/test/orm/model-has-many.spec.ts b/test/orm/model-has-many.spec.ts index 83100485..4d904e30 100644 --- a/test/orm/model-has-many.spec.ts +++ b/test/orm/model-has-many.spec.ts @@ -2044,6 +2044,9 @@ test.group('Model | HasMany | withCount', (group) => { @column({ isPrimary: true }) public id: number + @column() + public username: string + @hasMany(() => Post) public posts: HasMany } @@ -2071,8 +2074,11 @@ test.group('Model | HasMany | withCount', (group) => { User.boot() const user = await User.firstOrFail() + assert.equal(user.username, 'virk') + await user.loadCount('posts') + assert.equal(user.username, 'virk') assert.deepEqual(Number(user.$extras.posts_count), 2) })