Skip to content

Commit

Permalink
fix: retain existing attributes when calling loadCount on the model i…
Browse files Browse the repository at this point in the history
…nstance

Fixes: #786
  • Loading branch information
thetutlage committed Mar 2, 2022
1 parent 27e1dfd commit 0e19c53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Orm/Relations/AggregatesLoader/LazyLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class LazyLoadAggregates<Model extends LucidRow>
* Execute query
*/
public async exec() {
const result = await this.query.first()
const result = await this.query.pojo<any>().first()
if (!result) {
return
}
Expand Down
6 changes: 6 additions & 0 deletions test/orm/model-has-many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Post>
}
Expand Down Expand Up @@ -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)
})

Expand Down

0 comments on commit 0e19c53

Please sign in to comment.