mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 15:26:02 +00:00
fix: nest append (#194)
This commit is contained in:
parent
8b4d59ee97
commit
86e0f071e4
@ -71,6 +71,16 @@ describe('repository find', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('append with associations', async () => {
|
||||||
|
const users = await User.repository.findAndCount({
|
||||||
|
appends: ['posts', 'posts.comments'],
|
||||||
|
});
|
||||||
|
|
||||||
|
const user = users[0][0];
|
||||||
|
// @ts-ignore
|
||||||
|
expect(user.get('posts')[0].get('comments')).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
describe('findOne', () => {
|
describe('findOne', () => {
|
||||||
test('find one with attribute', async () => {
|
test('find one with attribute', async () => {
|
||||||
const user = await User.repository.findOne({
|
const user = await User.repository.findOne({
|
||||||
|
@ -195,7 +195,18 @@ export class OptionsParser {
|
|||||||
// appends: ['posts']
|
// appends: ['posts']
|
||||||
// appends: ['posts.title']
|
// appends: ['posts.title']
|
||||||
// All of these can be seen as last level
|
// All of these can be seen as last level
|
||||||
const lastLevel = appendFields.length <= 2;
|
let lastLevel: boolean = false;
|
||||||
|
|
||||||
|
if (appendFields.length == 1) {
|
||||||
|
lastLevel = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appendFields.length == 2) {
|
||||||
|
const associationModel = associations[appendFields[0]].target;
|
||||||
|
if (associationModel.rawAttributes[appendFields[1]]) {
|
||||||
|
lastLevel = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// find association index
|
// find association index
|
||||||
if (queryParams['include'] == undefined) {
|
if (queryParams['include'] == undefined) {
|
||||||
@ -230,8 +241,10 @@ export class OptionsParser {
|
|||||||
attributes = [];
|
attributes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const attributeName = appendFields[1];
|
||||||
|
|
||||||
// push field to it
|
// push field to it
|
||||||
attributes.push(appendFields[1]);
|
attributes.push(attributeName);
|
||||||
} else {
|
} else {
|
||||||
// if attributes is empty array, change it to object
|
// if attributes is empty array, change it to object
|
||||||
if (Array.isArray(attributes) && attributes.length == 0) {
|
if (Array.isArray(attributes) && attributes.length == 0) {
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
ModelCtor,
|
ModelCtor,
|
||||||
Op,
|
Op,
|
||||||
Transaction,
|
Transaction,
|
||||||
UpdateOptions as SequelizeUpdateOptions
|
UpdateOptions as SequelizeUpdateOptions,
|
||||||
} from 'sequelize';
|
} from 'sequelize';
|
||||||
import { Collection } from './collection';
|
import { Collection } from './collection';
|
||||||
import { Database } from './database';
|
import { Database } from './database';
|
||||||
|
Loading…
Reference in New Issue
Block a user