Currently the example below:
use cot::db::ForeignKey;
use cot::{db, Auto, LimitedString};
#[model]
pub struct Product {
#[model(primary_key)]
id: Auto<i64>,
#[model(unique)]
sku: LimitedString<64>,
name: LimitedString<255>,
price_cents: i64,
stock: i32,
is_available: bool,
}
#[model]
pub struct Order {
#[model(primary_key)]
id: Auto<i64>,
customer: ForeignKey<Customer>,
product: ForeignKey<Product>,
quantity: i32,
is_fulfilled: bool,
}
async fn save_order(db: Database) -> cot::Result<()> {
let mut order = Order {
id: Auto::default(),
product: ForeignKey::PrimaryKey(Auto::fixed(1)),
quantity: 1,
is_fulfilled: false,
};
order.save(db).await?;
}
...
Will return a UniqueViolation Error when the product_id being referenced here does not exist. It should say the ID does not exist.
Currently the example below:
Will return a
UniqueViolationError when theproduct_idbeing referenced here does not exist. It should say the ID does not exist.