mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
10 KiB
10 KiB
toc
toc |
---|
menu |
Field Types
Field abstract
RelationField abstract
HasOneField
interface HasOneFieldOptions {
type: 'hasOne';
/**
* The name of the field to use as the key for the association in the source table. Defaults to the primary
* key of the source table
*/
sourceKey?: string;
/**
* A string or a data type to represent the identifier in the table
*/
keyType?: DataType;
/**
* The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If
* you create multiple associations between the same tables, you should provide an alias to be able to
* distinguish between them. If you provide an alias when creating the assocition, you should provide the
* same alias when eager loading and when getting associated models. Defaults to the singularized name of
* target
*/
as?: string | { singular: string; plural: string };
/**
* The name of the foreign key in the target table or an object representing the type definition for the
* foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property
* to set the name of the column. Defaults to the name of source + primary key of source
*/
foreignKey?: string | ForeignKeyOptions;
/**
* What happens when delete occurs.
*
* Cascade if this is a n:m, and set null if it is a 1:m
*
* @default 'SET NULL' or 'CASCADE'
*/
onDelete?: string;
/**
* What happens when update occurs
*
* @default 'CASCADE'
*/
onUpdate?: string;
/**
* Should on update and on delete constraints be enabled on the foreign key.
*/
constraints?: boolean;
foreignKeyConstraint?: boolean;
scope?: AssociationScope;
/**
* If `false` the applicable hooks will not be called.
* The default value depends on the context.
*/
hooks?: boolean;
}
HasManyField
interface HasManyFieldOptions {
type: 'hasMany';
/**
* The name of the field to use as the key for the association in the source table. Defaults to the primary
* key of the source table
*/
sourceKey?: string;
/**
* A string or a data type to represent the identifier in the table
*/
keyType?: DataType;
/**
* The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If
* you create multiple associations between the same tables, you should provide an alias to be able to
* distinguish between them. If you provide an alias when creating the assocition, you should provide the
* same alias when eager loading and when getting associated models. Defaults to the singularized name of
* target
*/
as?: string | { singular: string; plural: string };
/**
* The name of the foreign key in the target table or an object representing the type definition for the
* foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property
* to set the name of the column. Defaults to the name of source + primary key of source
*/
foreignKey?: string | ForeignKeyOptions;
/**
* What happens when delete occurs.
*
* Cascade if this is a n:m, and set null if it is a 1:m
*
* @default 'SET NULL' or 'CASCADE'
*/
onDelete?: string;
/**
* What happens when update occurs
*
* @default 'CASCADE'
*/
onUpdate?: string;
/**
* Should on update and on delete constraints be enabled on the foreign key.
*/
constraints?: boolean;
foreignKeyConstraint?: boolean;
scope?: AssociationScope;
/**
* If `false` the applicable hooks will not be called.
* The default value depends on the context.
*/
hooks?: boolean;
}
BelongsToField
interface BelongsToFieldOptions {
type: 'belongsTo';
/**
* The name of the field to use as the key for the association in the target table. Defaults to the primary
* key of the target table
*/
targetKey?: string;
/**
* A string or a data type to represent the identifier in the table
*/
keyType?: DataType;
/**
* The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If
* you create multiple associations between the same tables, you should provide an alias to be able to
* distinguish between them. If you provide an alias when creating the assocition, you should provide the
* same alias when eager loading and when getting associated models. Defaults to the singularized name of
* target
*/
as?: string | { singular: string; plural: string };
/**
* The name of the foreign key in the target table or an object representing the type definition for the
* foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property
* to set the name of the column. Defaults to the name of source + primary key of source
*/
foreignKey?: string | ForeignKeyOptions;
/**
* What happens when delete occurs.
*
* Cascade if this is a n:m, and set null if it is a 1:m
*
* @default 'SET NULL' or 'CASCADE'
*/
onDelete?: string;
/**
* What happens when update occurs
*
* @default 'CASCADE'
*/
onUpdate?: string;
/**
* Should on update and on delete constraints be enabled on the foreign key.
*/
constraints?: boolean;
foreignKeyConstraint?: boolean;
scope?: AssociationScope;
/**
* If `false` the applicable hooks will not be called.
* The default value depends on the context.
*/
hooks?: boolean;
}
BelongsToManyField
interface BelongsToManyFieldOptions {
type: 'belongsToMany';
/**
* The name of the table that is used to join source and target in n:m associations. Can also be a
* sequelize model if you want to define the junction table yourself and add extra attributes to it.
*/
through: ModelType | string | ThroughOptions;
/**
* The name of the foreign key in the join table (representing the target model) or an object representing
* the type definition for the other column (see `Sequelize.define` for syntax). When using an object, you
* can add a `name` property to set the name of the colum. Defaults to the name of target + primary key of
* target
*/
otherKey?: string | ForeignKeyOptions;
/**
* The name of the field to use as the key for the association in the source table. Defaults to the primary
* key of the source table
*/
sourceKey?: string;
/**
* The name of the field to use as the key for the association in the target table. Defaults to the primary
* key of the target table
*/
targetKey?: string;
/**
* Should the join model have timestamps
*/
timestamps?: boolean;
/**
* The unique key name to override the autogenerated one when primary key is not present on through model
*/
uniqueKey?: string;
/**
* A key/value set that will be used for association create and find defaults on the target.
* (sqlite not supported for N:M)
*/
scope?: AssociationScope;
/**
* The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If
* you create multiple associations between the same tables, you should provide an alias to be able to
* distinguish between them. If you provide an alias when creating the assocition, you should provide the
* same alias when eager loading and when getting associated models. Defaults to the singularized name of
* target
*/
as?: string | { singular: string; plural: string };
/**
* The name of the foreign key in the target table or an object representing the type definition for the
* foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property
* to set the name of the column. Defaults to the name of source + primary key of source
*/
foreignKey?: string | ForeignKeyOptions;
/**
* What happens when delete occurs.
*
* Cascade if this is a n:m, and set null if it is a 1:m
*
* @default 'SET NULL' or 'CASCADE'
*/
onDelete?: string;
/**
* What happens when update occurs
*
* @default 'CASCADE'
*/
onUpdate?: string;
/**
* Should on update and on delete constraints be enabled on the foreign key.
*/
constraints?: boolean;
foreignKeyConstraint?: boolean;
/**
* If `false` the applicable hooks will not be called.
* The default value depends on the context.
*/
hooks?: boolean;
}
BooleanField
interface BooleanFieldOptions {
type: 'boolean';
}
StringField
interface StringFieldOptions {
type: 'string';
length?: number;
binary?: boolean;
}
TextField
type TextLength = 'tiny' | 'medium' | 'long';
interface TextFieldOptions {
type: 'text';
length?: TextLength;
}
IntegerField
interface IntegerFieldOptions {
type: 'integer';
length?: number;
zerofill?: boolean;
unsigned?: boolean;
}
FloatField
interface FloatFieldOptions {
type: 'float';
length?: number;
decimals?: number;
}
DoubleField
interface DoubleFieldOptions {
type: 'double';
length?: number;
decimals?: number;
}
RealField
interface RealFieldOptions {
type: 'real';
length?: number;
decimals?: number;
}
DecimalField
interface DecimalFieldOptions {
type: 'decimal';
precision?: number;
scale?: number;
}
DateField
interface DateFieldOptions {
type: 'date';
}
TimeField
interface TimeFieldOptions {
type: 'time';
}
JsonField
interface JsonFieldOptions {
type: 'json';
}
JsonbField
interface JsonbFieldOptions {
type: 'jsonb';
}
VirtualField
interface VirtualFieldOptions {
type: 'virtual';
}
SortField
interface SortFieldOptions {
type: 'sort';
}
PasswordField
interface PasswordFieldOptions {
type: 'password';
}
RadioField
interface RadioFieldOptions {
type: 'radio';
}
UIDField
interface UIDFieldOptions {
type: 'uid';
}
UUIDField
interface UUIDFieldOptions {
type: 'uuid';
}
CreatedByField
interface CreatedByFieldOptions {
type: 'createdBy';
}
UpdatedByField
interface UpdatedByFieldOptions {
type: 'updatedBy';
}