fix: append belongs to association with fields (#1894)

This commit is contained in:
ChengLei Shao 2023-05-20 21:31:27 +08:00 committed by GitHub
parent ccdc05b30b
commit aabc681245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -440,6 +440,15 @@ describe('repository find', () => {
expect(Object.keys(data)).toEqual(['id', 'posts']);
expect(Object.keys(data['posts'])).not.toContain('id');
});
test('find one with appends', async () => {
const profile = await Profile.repository.findOne({
filterByTk: 1,
appends: ['user.name'],
});
expect(profile.get('user').get('name')).toEqual('u1');
});
});
describe('find', () => {

View File

@ -76,10 +76,10 @@ export class EagerLoadingTree {
}
if (associationType == 'BelongsTo') {
const { sourceKey, foreignKey } = association;
const { targetKey, foreignKey } = association;
pushAttribute(eagerLoadingTreeParent, foreignKey);
pushAttribute(child, sourceKey);
pushAttribute(child, targetKey);
}
eagerLoadingTreeParent.children.push(child);