My current table structure looks like this:
--changeset 0004-order:ccushing
create table if not exists "order"."order"
(
id uuid primary key not null default uuid_generate_v4(),
state uuid references "order".order_status
);
--changeset 0004-h0-table-order_event_type:ccushing
create table if not exists "order".order_event_type
(
id uuid primary key not null default uuid_generate_v4(),
key text unique not null
);
--changeset 0004-h1-table-order_event:ccushing
create table if not exists "order".order_event
(
id uuid primary key not null default uuid_generate_v4(),
order_id uuid not null references "order"."order" (id),
event_type uuid not null references "order".order_event_type (id),
event jsonb not null,
unique (order_id, event),
unique (order_id, event_type)
);
I am looking to create a new OrderEventEntity
, but I want to avoid loading the Order
object since I only need the order_id
in the event.
@Entity('order.order_event')
export default class OrderEventEntity implements Identifiable<string> {
@PrimaryGeneratedColumn({ type: 'uuid' })
readonly id!: string;
@ManyToOne(() => OrderEventTypeEntity, ({ event }) => event)
readonly eventType!: string;
@ManyToOne(() => OrderEntity, ({ events }) => events)
readonly order!: OrderEntity;
}
Is it possible for me to achieve this by creating a new OrderEventEntity
and saving it without loading the entire Order
?
const order = new Order({ id: 1234 })
repo.save( new OrderEventEntity({ order: order, ... })
Or is there another way, maybe with some partial load, that allows me to maintain the OneToMany relationship while only having access to the order id?