* feat: filter by target key * fix: repository test * change type name * chore: test * change PrimaryKey type to TargetKey * rename filterTargetKey * rename variables * change option parser constructor * add option parser targetKey * change filter parser constructor * fix: custom model Co-authored-by: chenos <chenlinxh@gmail.com>
34 lines
698 B
TypeScript
34 lines
698 B
TypeScript
import { BaseFieldOptions, Field } from './field';
|
|
|
|
export interface BaseRelationFieldOptions extends BaseFieldOptions {}
|
|
|
|
export abstract class RelationField extends Field {
|
|
/**
|
|
* target relation name
|
|
*/
|
|
get target() {
|
|
const { target, name } = this.options;
|
|
return target || name;
|
|
}
|
|
|
|
get foreignKey() {
|
|
return this.options.foreignKey;
|
|
}
|
|
|
|
get sourceKey() {
|
|
return this.options.sourceKey;
|
|
}
|
|
|
|
get targetKey() {
|
|
return this.options.targetKey || this.TargetModel.primaryKeyAttribute;
|
|
}
|
|
|
|
/**
|
|
* get target model from database by it's name
|
|
* @constructor
|
|
*/
|
|
get TargetModel() {
|
|
return this.context.database.sequelize.models[this.target];
|
|
}
|
|
}
|