zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 89 forks source link

[Bug] Delegate model not returning extend model fields in nested include #1645

Closed harryfinn closed 1 month ago

harryfinn commented 1 month ago

Description and expected behavior As per discord help post (thread id: 1271572119838261270)

I've have a base model called BaseOrder which I extend into Order and GuestOrder models.

Within BaseOrder I have a 1-1 relationship with BillingAddress and ShippingAddress models, which extend from an OrderAddress model.

I'm running the following update statement transaction (via an enhanced zenstack prisma instance as the transaction):

const parentOrder = await tx.order.update({
    where: { id: parentOrder.id },
    include: {
        lineItems: true,
        billingAddress: true,
        shippingAddress: true,
    },
    data: {
        type: 'CAMPAIGN',
        campaignId: campaignOrder.campaignId,
        lineItems: {
            createMany: {
                data: orderLineItems,
            },
        },
    },
});

The returning data includes all the fields in the BaseOrder model (for Order) and for the lineItems (which are instances of OrderItem model), however the nested BillingAddress and ShippingAddress models only return the relationship ids that are set within these extended models, and non of the fields against OrderAddress

Any ideas on what I'm doing wrong or if this is an issue in Zenstack? - I'm using v2.4.1

Issue raised after @jiashengguo reviewed and confirmed this is a bug.

Environment (please complete the following information):

Additional context Example schema.zmodel file attached (rename/change file extension from .txt - had to change in order for upload to github) schema.zmodel.txt

ymc9 commented 1 month ago

Fixed in 2.5.0