-
-
Notifications
You must be signed in to change notification settings - Fork 44
Show better error message when creating ForeignKey::PrimaryKey with non-existent ID #541
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request