Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial loading hint for embedded property is ignored #3673

Closed
B4nan opened this issue Oct 31, 2022 Discussed in #3672 · 0 comments
Closed

Partial loading hint for embedded property is ignored #3673

B4nan opened this issue Oct 31, 2022 Discussed in #3672 · 0 comments
Labels
bug Something isn't working

Comments

@B4nan
Copy link
Member

B4nan commented Oct 31, 2022

Discussed in #3672

Originally posted by JeongJuhyeon October 31, 2022
Using

  • mikro-orm 5.4.2
  • PostgreSQL
  • ts-morph

tl;dr Trying to partially fetch embeddable but the properties aren't being selected, they don't appear in the generated query.

Entity and Embeddable:

@Embeddable()
export class ReservationRestrictions {
  @Property()
  paxMin!: number;

  @Property()
  paxMax!: number;

  @Property()
  slotGapMinutes!: number;

  @Property()
  daysReservableInFuture!: number;

  @Property({ type: 'json', nullable: false })
  openingHours: Partial<Record<DayNumber, OpeningHours>> = {};

  constructor(dto: CreateStoreDto) {
    this.daysReservableInFuture =
      dto.reservationRestrictions.daysReservableInFuture;
    this.paxMax = dto.reservationRestrictions.paxMax;
    this.paxMin = dto.reservationRestrictions.paxMin;
    this.slotGapMinutes = dto.reservationRestrictions.slotGapMinutes;
    this.openingHours = dto.reservationRestrictions.openingHours;
  }
}

@Entity()
export class Store extends CustomBaseEntity {
  @OneToMany(() => Reservation, (reservation) => reservation.store)
  reservations = new Collection<Reservation>(this);

  @Embedded()
  storeInfo!: StoreInfo;

  @OneToOne(() => StoreOwner, (storeOwner) => storeOwner.store)
  owner!: StoreOwner;

  constructor(owner: StoreOwner, dto: CreateStoreDto) {
    super();
    this.owner = owner;
    this.reservationRestrictions = new ReservationRestrictions(dto);
    this.storeInfo = new StoreInfo(dto);
  }
}

The below call

    this.storeRepository.findAll({
      fields: [
        'id',
        {
          storeInfo: ['name', 'subtitle', 'cuisine', 'pictures'],
        },
      ],
    });

Produces the following query:
select "s0"."id" from "store" as "s0"
I'm not sure if this is intentional or a bug. For reference, if I select the embeddable as a field (so all properties are pulled) it works fine:

this.storeRepository.findAll({
      fields: ['id', 'storeInfo'],
    });

select "s0"."id", "s0"."store_info_name", "s0"."store_info_subtitle", "s0"."store_info_pictures", "s0"."store_info_description", "s0"."store_info_address", "s0"."store_info_phone", "s0"."store_info_opening_hours", "s0"."store_info_city", "s0"."store_info_cuisine" from "store" as "s0"

@B4nan B4nan added the bug Something isn't working label Oct 31, 2022
@B4nan B4nan closed this as completed in 0c33e00 Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant