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

feat: @set and related model fields #1718

Merged
merged 4 commits into from
Feb 6, 2025

Conversation

davenewza
Copy link
Contributor

@set and related model fields

@set has been limited to just setting a model field from actions inputs and ctx. This extends @set functionality to support looking up fields in related models in both create and update actions.

A nice example of this would be to set the price of a purchase order once-off from a product's standard price:

model Order {
    fields {
        price Decimal
        quantity Number
        product Product
        total Decimal @computed(order.price * order.quantity)
    }
    actions {
        create createOrder() with (product.id, quantity, customer.id) {
            @set(order.price = order.product.standardPrice)
        }
        update resetOrderPrice(id) {
            @set(order.price = order.product.standardPrice)
        }
    }
}

model Product {
    fields {     
        standardPrice Decimal
    }
}

Note that we do not support looking up 1:M values yet.

@davenewza davenewza merged commit 5dde8a6 into teamkeel:main Feb 6, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants