mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 09:45:18 +00:00
fix: filterTargetKey
This commit is contained in:
parent
60aa6babf5
commit
5b2f38da14
@ -151,12 +151,14 @@ export class Collection<
|
||||
}
|
||||
|
||||
get filterTargetKey() {
|
||||
const targetKey = lodash.get(this.options, 'filterTargetKey', this.model.primaryKeyAttribute);
|
||||
if (!targetKey && this.model.rawAttributes['id']) {
|
||||
return 'id';
|
||||
const targetKey = this.options?.filterTargetKey;
|
||||
if (targetKey && this.model.getAttributes()[targetKey]) {
|
||||
return targetKey;
|
||||
}
|
||||
|
||||
return targetKey;
|
||||
if (this.model.primaryKeyAttributes.length > 1) {
|
||||
return null;
|
||||
}
|
||||
return this.model.primaryKeyAttribute;
|
||||
}
|
||||
|
||||
get name() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database, { Collection, MagicAttributeModel, SyncOptions, Transactionable } from '@nocobase/database';
|
||||
import lodash from 'lodash';
|
||||
import { FieldModel } from './field';
|
||||
import { QueryInterfaceDropTableOptions } from 'sequelize';
|
||||
import { FieldModel } from './field';
|
||||
|
||||
interface LoadOptions extends Transactionable {
|
||||
// TODO
|
||||
@ -15,6 +15,15 @@ export class CollectionModel extends MagicAttributeModel {
|
||||
return (<any>this.constructor).database;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
const json = super.toJSON();
|
||||
if (!json.filterTargetKey) {
|
||||
const collection = this.db.getCollection(json.name);
|
||||
json.filterTargetKey = collection?.filterTargetKey;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
async load(loadOptions: LoadOptions = {}) {
|
||||
const { skipExist, skipField, resetFields, transaction } = loadOptions;
|
||||
const name = this.get('name');
|
||||
|
Loading…
Reference in New Issue
Block a user