N
N
Ne7Le4Der2021-11-01 18:04:13
SQL
Ne7Le4Der, 2021-11-01 18:04:13

How to make a proper Sequelize request?

@Table({
    tableName: 'jobs',
    timestamps: true
})
export class Job extends Model {
    @Column({
        type: DataType.UUID,
        defaultValue: UUIDV4,
        primaryKey: true,
        unique: true,
        allowNull: false
    })
    id: string;

    @Index('instrument_id')
    @Column({
        type: DataType.STRING,
        allowNull: false
    })
    instrument_id: string;

    @HasMany(() => Candle)
    candles: Candle[]
}

@Table({
    tableName: 'candles',
    timestamps: true
})
export class Candle extends Model {
    @Column({
        type: DataType.UUID,
        defaultValue: UUIDV4,
        primaryKey: true,
        unique: true,
        allowNull: false
    })
    id: string;

    @BelongsTo(() => Job)
    job: Job

    @ForeignKey(() => Job)
    job_id: string
}


How to make a request to get a response of the form:
Job.id | Job.instrument_id | Кол-во строк с job_id=Job.id в таблице Candle

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question