SeaQL / SeaQL/sea-orm

Before_save hooks doesn't work on 1.1.13

Open
#2,646 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-info
Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

before_save fuction like in doc (https://www.sea-ql.org/SeaORM/docs/next/generate-entity/entity-structure/):

async fn before_save<C>(self, db: &C, insert: bool) -> Result<Self, DbErr>
    where
        C: ConnectionTrait,
    {
        if self.price.as_ref() <= &0.0 {
            Err(DbErr::Custom(format!(
                "[before_save] Invalid Price, insert: {}",
                insert
            )))
        } else {
            Ok(self)
        }
    }

this could not compile, got err:

error[E0195]: lifetime parameters or bounds on method before_save do not match the trait declaration

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the before_save example on the linked entity-structure documentation page and compare it with the trait declaration used by SeaORM 1.1.13. Reproduce the reported lifetime error, then verify that the documented hook signature and example compile against that version.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.