muiltiple images in carousel
This commit is contained in:
@@ -37,15 +37,15 @@ pub async fn first_for(ctx: &AppContext, product_id: i32) -> Result<Option<Strin
|
||||
.map(|image| image.image_id))
|
||||
}
|
||||
|
||||
/// Number of images already attached to a product, used to position new uploads.
|
||||
///
|
||||
/// Takes a connection rather than the `AppContext` so it can run on an open
|
||||
/// transaction; calling it on `ctx.db` while a transaction holds the pool's only
|
||||
/// connection would deadlock the pool.
|
||||
pub async fn count_for<C: ConnectionTrait>(db: &C, product_id: i32) -> Result<i32> {
|
||||
use sea_orm::PaginatorTrait;
|
||||
/// All of a product's images in display order (lowest position first). Takes a
|
||||
/// connection so it can run inside the update transaction.
|
||||
pub async fn for_product<C: ConnectionTrait>(
|
||||
db: &C,
|
||||
product_id: i32,
|
||||
) -> Result<Vec<Model>> {
|
||||
Ok(Entity::find()
|
||||
.filter(Column::ProductId.eq(product_id))
|
||||
.count(db)
|
||||
.await? as i32)
|
||||
.order_by_asc(Column::Position)
|
||||
.all(db)
|
||||
.await?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user