sequelize/sequelize-typescript

it only brings me a record in one to many

ArthurQR98 opened this issue · 1 comments

Issue

Currently I have 2 tables that are in a one-to-many relationship and the problem is that it only brings me one record of that union.

Models:

@Table({
  tableName: 'visit_occurrence_pending_billing',
  timestamps: false,
})
export class visitOccurrencePendingBilling
  extends Model<
    visitOccurrencePendingBillingAttributes,
    visitOccurrencePendingBillingAttributes
  >
  implements visitOccurrencePendingBillingAttributes
{
  @Column({
    field: 'medical_record_number',
    allowNull: true,
    type: DataType.INTEGER,
  })
  medicalRecordNumber?: number;

  @Column({
    field: 'person_name',
    allowNull: true,
    type: DataType.STRING,
  })
  personName?: string;

  @Column({
    field: 'person_first_name',
    allowNull: true,
    type: DataType.STRING,
  })
  personFirstName?: string;

  @Column({
    field: 'person_last_name',
    allowNull: true,
    type: DataType.STRING,
  })
  personLastName?: string;

  @Column({
    field: 'person_second_last_name',
    allowNull: true,
    type: DataType.STRING,
  })
  personSecondLastName?: string;

  @Column({
    field: 'person_id',
    allowNull: true,
    type: DataType.STRING,
  })
  personId?: string;

  @PrimaryKey
  @Column({
    field: 'visit_occurrence_id',
    allowNull: true,
    type: DataType.STRING,
  })
  visitOccurrenceId?: string;

  @Column({
    field: 'visit_occurrence_source_concept_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  visitOccurrenceSourceConceptId?: number;

  @Column({
    field: 'visit_type_source_value',
    allowNull: true,
    type: DataType.STRING,
  })
  visitTypeSourceValue?: string;

  @Column({
    field: 'start_date',
    allowNull: true,
    type: DataType.STRING,
  })
  startDate?: string;

  @Column({
    field: 'service_provision',
    allowNull: true,
    type: DataType.STRING,
  })
  serviceProvision?: string;

  @Column({
    field: 'payer_source_value',
    allowNull: true,
    type: DataType.STRING,
  })
  payerSourceValue?: string;

  @Column({
    field: 'plan_source_value',
    allowNull: true,
    type: DataType.STRING,
  })
  planSourceValue?: string;

  @Column({
    field: 'benefit_name',
    allowNull: true,
    type: DataType.STRING,
  })
  benefitName?: string;

  @Column({
    field: 'company_name',
    allowNull: true,
    type: DataType.STRING,
  })
  companyName?: string;

  @Column({
    field: 'authorization_code',
    allowNull: true,
    type: DataType.STRING,
  })
  authorizationCode?: string;

  @Column({
    field: 'origin_visit_occurrence',
    allowNull: true,
    type: DataType.STRING,
  })
  originVisitOccurrence?: string;

  @Column({
    field: 'user_admission_id',
    allowNull: true,
    type: DataType.STRING,
  })
  userAdmissionId?: string;

  @Column({
    field: 'user_admission_source_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  userAdmissionSourceId?: number;

  @Column({
    field: 'inscription_country_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  inscriptionCountryId?: number;

  @Column({
    field: 'his_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  hisId?: number;

  @Column({
    field: 'payer_id',
    allowNull: true,
    type: DataType.STRING,
  })
  payerId?: string;

  @Column({
    field: 'payer_source_concept_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  payerSourceConceptId?: number;

  @Column({
    field: 'payer_plan_id',
    allowNull: true,
    type: DataType.STRING,
  })
  payerPlanId?: string;

  @Column({
    field: 'payer_plan_source_concept_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  payerPlanSourceConceptId?: number;

  @Column({
    field: 'care_site_source_concept_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  careSiteSourceConceptId?: number;

  @ForeignKey(() => careSite)
  @Column({
    field: 'care_site_id',
    allowNull: true,
    type: DataType.STRING,
  })
  careSiteId?: string;

  @ForeignKey(() => userProfiles)
  @Column({
    field: 'username_user_admission_source_value',
    allowNull: true,
    type: DataType.STRING,
  })
  usernameUserAdmissionSourceValue?: string;

  @Column({
    field: 'benefit_source_concept_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  benefitSourceConceptId?: number;

  @Column({
    field: 'closing_date',
    allowNull: true,
    type: DataType.STRING,
  })
  closingDate?: string;

  @Column({
    allowNull: true,
    type: DataType.STRING,
  })
  mechanism?: string;

  @Column({
    field: 'service_source_value',
    allowNull: true,
    type: DataType.STRING,
  })
  serviceSourceValue?: string;

  @Column({
    field: 'erp_invoice_number',
    allowNull: true,
    type: DataType.STRING,
  })
  erpInvoiceNumber?: string;

  @Column({
    field: 'visit_type_source_long_value',
    allowNull: true,
    type: DataType.STRING,
  })
  visitTypeSourceLongValue?: string;

  @Column({
    field: 'company_source_concept_id',
    allowNull: true,
    type: DataType.INTEGER,
  })
  companySourceConceptId?: number;

  @HasMany(() => visitOccurrencePendingDocuments)
  documents: visitOccurrencePendingDocuments[];
  @BelongsTo(() => careSite)
  care: careSite;
}
@Table({
  tableName: 'visit_occurrence_pending_documents',
  timestamps: false,
})
export class visitOccurrencePendingDocuments
  extends Model<
    visitOccurrencePendingDocumentsAttributes,
    visitOccurrencePendingDocumentsAttributes
  >
  implements visitOccurrencePendingDocumentsAttributes
{
  @PrimaryKey
  @ForeignKey(() => visitOccurrencePendingBilling)
  @Column({
    field: 'visit_occurrence_id',
    allowNull: true,
    type: DataType.STRING,
  })
  visitOccurrenceId?: string;

  @Column({
    field: 'payer_id',
    allowNull: true,
    type: DataType.STRING,
  })
  payerId?: string;

  @Column({
    field: 'payer_plan_id',
    allowNull: true,
    type: DataType.STRING,
  })
  payerPlanId?: string;

  @Column({
    field: 'document_type_admin',
    allowNull: true,
    type: DataType.STRING,
  })
  documentTypeAdmin?: string;

  @Column({
    field: 'type_meeting',
    allowNull: true,
    type: DataType.STRING,
  })
  typeMeeting?: string;

  @Column({
    field: 'phase_proc',
    allowNull: true,
    type: DataType.STRING,
  })
  phaseProc?: string;

  @Column({
    field: 'document_type_admin_replaced',
    allowNull: true,
    type: DataType.STRING,
  })
  documentTypeAdminReplaced?: string;

  @BelongsTo(() => visitOccurrencePendingBilling)
  visit_ids: visitOccurrencePendingBilling;
}

Versions

  • sequelize: 6.37.2
  • sequelize-typescript: 2.1.6
  • typescript: 5.1.6
  • nestjs/sequelize: 10.0.1

Issue type

  • bug report
  • feature request

Actual behavior

{
        "medicalRecordNumber": 1001354,
        "personName": "XSFNYRNFMR XLMGIVIZH, ILYVIGL XZIOLH",
        "visitTypeSourceLongValue": "CONSULTAS EXTERNAS",
        "companySourceConceptId": null,
        "care": {
            "careSiteName": "XLMGIVIZH"
        },
        "documents": [
            {
                "visitOccurrenceId": "120739703",
                "payerId": "173",
                "payerPlanId": "1204",
                "documentTypeAdmin": "011",
                "typeMeeting": "ADM",
                "phaseProc": "1",
                "documentTypeAdminReplaced": "010,009"
            }
        ]
    }

Expected behavior

{
        "medicalRecordNumber": 1001354,
        "personName": "XSFNYRNFMR XLMGIVIZH, ILYVIGL XZIOLH",
        "visitTypeSourceLongValue": "CONSULTAS EXTERNAS",
        "companySourceConceptId": null,
        "care": {
            "careSiteName": "XLMGIVIZH"
        },
        "documents": [
            {
                "visitOccurrenceId": "120739703",
                "payerId": "173",
                "payerPlanId": "1204",
                "documentTypeAdmin": "011",
                "typeMeeting": "ADM",
                "phaseProc": "1",
                "documentTypeAdminReplaced": "010,009"
            },
            {
                "visitOccurrenceId": "120739703",
                "payerId": "173",
                "payerPlanId": "1204",
                "documentTypeAdmin": "002",
                "typeMeeting": "ADM",
                "phaseProc": "1",
                "documentTypeAdminReplaced": ""
            }
        ]
    }

Steps to reproduce

Related code

async findAllManagementReport(
    care_site: string,
    page: number
  ): Promise<any> {
    return this.visitOccurrencePendingBillingModel.findAll({
      where: {
        careSiteId: care_site
      },
      include: [
        {
          model: careSite,
          attributes: ['careSiteName'],
          required: true,
        },
        {
          model: visitOccurrencePendingDocuments,
        },
      ],
    });
  }
  • A sample application via GitHub (Best option, since its much easier for us to investigate, so that we can come back to you more recently)
  • A code snippet below (Please make sure, that the snippet at least includes tsconfig and the sequelize options)

-->

insert short code snippets here

I do have the same issue with my one-to-many relationships where it returns only 1 child attributes whereas I have 3 child attributes (3 rows) in my database.