feat(medusa): Use query relation load strategy on Carts (#3984)

This commit is contained in:
Oliver Windall Juhl authored and GitHub committed 2023-05-02 21:10:44 +02:00
1 parent 4e8045a0ac
commit b7a7826394
9 files changed
+33 -23

No files matched your search

+3 -11
View File
@@ -216,7 +216,6 @@
*/
import {
AfterLoad,
BeforeInsert,
Column,
Entity,
@@ -226,7 +225,7 @@ import {
ManyToMany,
ManyToOne,
OneToMany,
OneToOne,
OneToOne
} from "typeorm"
import { DbAwareColumn, resolveDbType } from "../utils/db-aware-column"
import {
@@ -234,6 +233,8 @@ import {
FeatureFlagDecorators,
} from "../utils/feature-flag-decorators"
import { SoftDeletableEntity } from "../interfaces/models/soft-deletable-entity"
import { generateEntityId } from "../utils/generate-entity-id"
import { Address } from "./address"
import { Customer } from "./customer"
import { Discount } from "./discount"
@@ -244,8 +245,6 @@ import { PaymentSession } from "./payment-session"
import { Region } from "./region"
import { SalesChannel } from "./sales-channel"
import { ShippingMethod } from "./shipping-method"
import { SoftDeletableEntity } from "../interfaces/models/soft-deletable-entity"
import { generateEntityId } from "../utils/generate-entity-id"
export enum CartType {
DEFAULT = "default",
@@ -391,13 +390,6 @@ export class Cart extends SoftDeletableEntity {
gift_card_total?: number
gift_card_tax_total?: number
@AfterLoad()
private afterLoad(): void {
if (this.payment_sessions) {
this.payment_session = this.payment_sessions.find((p) => p.is_selected)!
}
}
@BeforeInsert()
private beforeInsert(): void {
this.id = generateEntityId(this.id, "cart")
@@ -11,17 +11,17 @@ import {
PrimaryColumn,
} from "typeorm"
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
import { DbAwareColumn } from "../utils/db-aware-column"
import { FeatureFlagColumn } from "../utils/feature-flag-decorators"
import { generateEntityId } from "../utils/generate-entity-id"
import { Cart } from "./cart"
import { ClaimOrder } from "./claim-order"
import { DbAwareColumn } from "../utils/db-aware-column"
import { Order } from "./order"
import { Return } from "./return"
import { ShippingMethodTaxLine } from "./shipping-method-tax-line"
import { ShippingOption } from "./shipping-option"
import { Swap } from "./swap"
import { generateEntityId } from "../utils/generate-entity-id"
import { FeatureFlagColumn } from "../utils/feature-flag-decorators"
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
@Check(
`"claim_order_id" IS NOT NULL OR "order_id" IS NOT NULL OR "cart_id" IS NOT NULL OR "swap_id" IS NOT NULL OR "return_id" IS NOT NULL`
@@ -56,7 +56,7 @@ export class ShippingMethod {
@Column({ nullable: true })
cart_id: string
@ManyToOne(() => Cart)
@ManyToOne(() => Cart, (cart) => cart.shipping_methods)
@JoinColumn({ name: "cart_id" })
cart: Cart
+2 -2
View File
@@ -10,11 +10,11 @@ import {
import { BaseEntity } from "../interfaces/models/base-entity"
import { DbAwareColumn } from "../utils/db-aware-column"
import { generateEntityId } from "../utils/generate-entity-id"
import { Product } from "./product"
import { ProductType } from "./product-type"
import { Region } from "./region"
import { ShippingOption } from "./shipping-option"
import { generateEntityId } from "../utils/generate-entity-id"
@Entity()
export class TaxRate extends BaseEntity {
@@ -30,7 +30,7 @@ export class TaxRate extends BaseEntity {
@Column()
region_id: string
@ManyToOne(() => Region)
@ManyToOne(() => Region, (region) => region.tax_rates)
@JoinColumn({ name: "region_id" })
region: Region