On Wed, Feb 10, 2021 at 8:37 PM Dawid Janczak <[email protected]> wrote:
> Hello! > > I have a one_to_one relation between an order and transaction (`one_to_one > :transaction` inside `Order` class). In addition I have a FK constraint on > `order_id` on `transactions` table. Assigning the transaction with > `order.transaction = Transaction.new(attrs)` works just fine, but then when > I (incorrectly) try to add another one I'm getting a > `NotNullConstraintViolation` on `order_id` column. Is there a reason for > this and not raising `UniqueConstraintViolation`? > > Notice that this only happens if I use `order.transaction = > Transaction.new(attrs)` setter, if I instead do > `Transaction..create(attrs.merge(order_id: order.id))` I get the correct > error raised. > If you submit a INSERT query where the inserted row violates both a NOT NULL constraint and a UNIQUE constraint/index, which exception is raised is up to the database. It makes sense that the database would raise the NOT NULL constraint violation first as that is cheaper to check than a UNIQUE constraint/index. If you don't think that is what is going on, please post a minimal self contained example showing the problem. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSSfZr1UDtydZj3nHz2Jzd%3Dbd7xEy0o%2Bf1%3DPJ6tF%3DMKZ_bA%40mail.gmail.com.
