src/Connection/ConnectionManager.js
/**
     * Generate an EntitySchema object from decorator.
     *
     * @param {ReflectionClass} reflClass
     * @param {Entity} decorator
     * @param {NamingStrategyInterface} namingStrategy
     *
     * @private
     */
Generate an EntitySchema object from decorator.

@private
Generate an EntitySchema object from decorator . @private
* _loadFromDecorator(reflClass, decorator, namingStrategy) {
        const constructor = reflClass.getConstructor();
        const [ , table ] = reflClass.metadata.find(([ t ]) => t === Table) || [];
        let [ , inheritanceType ] = reflClass.metadata.find(([ t ]) => t === InheritanceType) || [];
        const [ , discriminatorColumn ] = reflClass.metadata.find(([ t ]) => t === DiscriminatorColumn) || [];
        const [ , discriminatorMap ] = reflClass.metadata.find(([ t ]) => t === DiscriminatorMap) || [];
        const indices = reflClass.metadata
            .filter(([ t ]) => t === Index)
            .map(([ , index ]) => ({
                name: index.name,
                columns: index.columns,
                synchronize: index.synchronize,
                unique: index.unique,
                spatial: index.spatial,
                fulltext: index.fulltext,
                where: index.where,
            }));
        const checks = reflClass.metadata
            .filter(([ t ]) => t === Check)
            .map(([ , check ]) => ({
                name: check.name,
                expression: check.expression,
            }));
        const exclusions = reflClass.metadata
            .filter(([ t ]) => t === Exclude)
            .map(([ , check ]) => ({
                name: check.name,
                expression: check.expression,
            }));
        let parent = reflClass;
        let columns = this._loadColumns(reflClass, namingStrategy);
        let relations = this._loadRelations(reflClass);
        while ((parent = parent.getParentClass())) {
            const [ , mappedSuperclass ] = parent.metadata.find(([ t ]) => t === MappedSuperclass) || [];
            if (! mappedSuperclass) {
                break;
            }
            columns = { ...this._loadColumns(parent, namingStrategy), ...columns };
            relations = { ...this._loadRelations(parent), ...relations };
        }
        inheritanceType = inheritanceType ? inheritanceType.type : undefined;
        yield new EntitySchema({
            columns,
            relations,
            target: constructor,
            extends: decorator.extends,
            name: decorator.name || reflClass.shortName,
            synchronize: decorator.synchronize,
            tableName: namingStrategy.tableName(decorator.name || reflClass.shortName, table ? table.name : undefined),
            database: table ? table.database : undefined,
            schema: table ? table.schema : undefined,
            type: table ? table.type : undefined,
            indices,
            checks,
            exclusions,
            repository: decorator.repository,
            inheritanceType,
            discriminatorColumn: discriminatorColumn && 'SINGLE_TABLE' === inheritanceType ? {
                type: discriminatorColumn.type,
                name: discriminatorColumn.name,
            } : undefined,
            discriminatorMap: discriminatorMap && 'SINGLE_TABLE' === inheritanceType ? discriminatorMap.map : undefined,
        });
    }
* _loadFromDecorator ( reflClass , decorator , namingStrategy ) { const constructor = reflClass . getConstructor ( ) ; const [ , table ] = reflClass . metadata . find ( ( [ t ] ) => t === Table ) || [ ] ; let [ , inheritanceType ] = reflClass . metadata . find ( ( [ t ] ) => t === InheritanceType ) || [ ] ; const [ , discriminatorColumn ] = reflClass . metadata . find ( ( [ t ] ) => t === DiscriminatorColumn ) || [ ] ; const [ , discriminatorMap ] = reflClass . metadata . find ( ( [ t ] ) => t === DiscriminatorMap ) || [ ] ; const indices = reflClass . metadata . filter ( ( [ t ] ) => t === Index ) . map ( ( [ , index ] ) => ( { name : index . name , columns : index . columns , synchronize : index . synchronize , unique : index . unique , spatial : index . spatial , fulltext : index . fulltext , where : index . where , } ) ) ; const checks = reflClass . metadata . filter ( ( [ t ] ) => t === Check ) . map ( ( [ , check ] ) => ( { name : check . name , expression : check . expression , } ) ) ; const exclusions = reflClass . metadata . filter ( ( [ t ] ) => t === Exclude ) . map ( ( [ , check ] ) => ( { name : check . name , expression : check . expression , } ) ) ; let parent = reflClass ; let columns = this . _loadColumns ( reflClass , namingStrategy ) ; let relations = this . _loadRelations ( reflClass ) ; while ( ( parent = parent . getParentClass ( ) ) ) { const [ , mappedSuperclass ] = parent . metadata . find ( ( [ t ] ) => t === MappedSuperclass ) || [ ] ; if ( ! mappedSuperclass ) { break ; } columns = { ... this . _loadColumns ( parent , namingStrategy ) , ... columns } ; relations = { ... this . _loadRelations ( parent ) , ... relations } ; } inheritanceType = inheritanceType ? inheritanceType . type : undefined ; yield new EntitySchema ( { columns , relations , target : constructor , extends : decorator . extends , name : decorator . name || reflClass . shortName , synchronize : decorator . synchronize , tableName : namingStrategy . tableName ( decorator . name || reflClass . shortName , table ? table . name : undefined ) , database : table ? table . database : undefined , schema : table ? table . schema : undefined , type : table ? table . type : undefined , indices , checks , exclusions , repository : decorator . repository , inheritanceType , discriminatorColumn : discriminatorColumn && 'SINGLE_TABLE' === inheritanceType ? { type : discriminatorColumn . type , name : discriminatorColumn . name , } : undefined , discriminatorMap : discriminatorMap && 'SINGLE_TABLE' === inheritanceType ? discriminatorMap . map : undefined , } ) ; }
Generate an EntitySchema object from decorator.
Generate an EntitySchema object from decorator .