Skip to main content

ModelExtensions

Trait ModelExtensions 

Source
pub trait ModelExtensions: Model + CrudOperations {
    // Provided methods
    async fn refresh(&mut self, pool: &Pool<Postgres>) -> ModelResult<()>
       where Self: Sized { ... }
    async fn exists(&self, pool: &Pool<Postgres>) -> ModelResult<bool>
       where Self: Sized { ... }
    async fn save(&mut self, pool: &Pool<Postgres>) -> ModelResult<()>
       where Self: Sized + Clone { ... }
    fn duplicate(&self) -> Self
       where Self: Sized + Clone { ... }
    fn supports_transactions() -> bool
       where Self: Sized { ... }
    fn is_dirty(&self) -> bool { ... }
    fn mark_clean(&mut self) { ... }
    fn dirty_fields(&self) -> Vec<&str> { ... }
}
Expand description

Extension trait for models with additional utility methods

Provided Methods§

Source

async fn refresh(&mut self, pool: &Pool<Postgres>) -> ModelResult<()>
where Self: Sized,

Refresh this model instance from the database

Source

async fn exists(&self, pool: &Pool<Postgres>) -> ModelResult<bool>
where Self: Sized,

Check if this model instance exists in the database

Source

async fn save(&mut self, pool: &Pool<Postgres>) -> ModelResult<()>
where Self: Sized + Clone,

Source

fn duplicate(&self) -> Self
where Self: Sized + Clone,

Create a clone of this model without the primary key (for duplication)

Source

fn supports_transactions() -> bool
where Self: Sized,

Placeholder for transaction-scoped model operations Will be fully implemented when derive macros are available

Source

fn is_dirty(&self) -> bool

Check if this model has been modified since last save/load Default implementation always returns true - override for dirty tracking

Source

fn mark_clean(&mut self)

Mark all fields as clean (not dirty) after save operations Default implementation is a no-op - override for dirty tracking

Source

fn dirty_fields(&self) -> Vec<&str>

Get list of modified fields since last save/load Default implementation returns empty - override for dirty tracking

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§