PrimaryKey auto_increment
This commit is contained in:
parent
991b04580c
commit
71d0cde771
@ -26,6 +26,12 @@ pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {
|
||||
Fruit,
|
||||
|
@ -27,6 +27,12 @@ pub enum PrimaryKey {
|
||||
FillingId,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {
|
||||
Cake,
|
||||
|
@ -26,6 +26,12 @@ pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
|
@ -28,6 +28,12 @@ pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
|
@ -45,8 +45,6 @@ pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenS
|
||||
}
|
||||
}
|
||||
|
||||
impl sea_orm::PrimaryKeyTrait for #ident {}
|
||||
|
||||
impl sea_orm::PrimaryKeyToColumn for #ident {
|
||||
type Column = Column;
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::{Database, DeleteResult, EntityTrait, ExecErr, Iterable, PrimaryKeyToColumn, Value};
|
||||
use crate::{
|
||||
Database, DeleteResult, EntityTrait, ExecErr, Iterable, PrimaryKeyToColumn, PrimaryKeyTrait,
|
||||
Value,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@ -258,7 +261,7 @@ where
|
||||
let exec = E::insert(am).exec(db);
|
||||
let res = exec.await?;
|
||||
// TODO: if the entity does not have auto increment primary key, then last_insert_id is a wrong value
|
||||
if res.last_insert_id != 0 {
|
||||
if <E::PrimaryKey as PrimaryKeyTrait>::auto_increment() && res.last_insert_id != 0 {
|
||||
let find = E::find_by(res.last_insert_id).one(db);
|
||||
let res = find.await;
|
||||
let model: Option<E::Model> = res.map_err(|_| ExecErr)?;
|
||||
|
@ -1,6 +1,8 @@
|
||||
use super::{ColumnTrait, IdenStatic, Iterable};
|
||||
|
||||
pub trait PrimaryKeyTrait: IdenStatic + Iterable {}
|
||||
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
|
||||
fn auto_increment() -> bool;
|
||||
}
|
||||
|
||||
pub trait PrimaryKeyToColumn {
|
||||
type Column: ColumnTrait;
|
||||
|
@ -27,6 +27,12 @@ pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {
|
||||
Fruit,
|
||||
|
@ -28,6 +28,12 @@ pub enum PrimaryKey {
|
||||
FillingId,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {
|
||||
Cake,
|
||||
|
@ -27,6 +27,12 @@ pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
|
@ -29,6 +29,12 @@ pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user