The pagination functionality is repeating items #4874
Answered
by
thetutlage
vandsonfalcao
asked this question in
Help
-
hi guys, sorry my english, im not fluent. i have a problem, how i said in title the pagination funcionality is repeating itens, i will send some screenshot for more details, I can not share a lot of the code but I will do the possible to give more details, please sorry if this is not the ideal channel for this subject. constroller method:async index({ request, response }: HttpContext) {
const { page, perPage } = await vine
.compile(
vine.object({
productId: vine.string().uuid().optional(),
onlyActive: vine.boolean().optional(),
withProduct: vine.boolean().optional(),
page: vine.number().optional(),
perPage: vine.number().optional(),
})
)
.validate(request.all())
let query = ProductImage.query()
const paginatedImages = await query.orderBy('description').paginate(page || 1, perPage || 10)
console.log({
page: paginatedImages.getMeta().currentPage,
itens: paginatedImages.all().map((i) => i.id),
})
return response.ok(paginatedImages)
} product model:import { BaseModel, column, computed, hasMany } from '@adonisjs/lucid/orm'
import type { HasMany } from '@adonisjs/lucid/types/relations'
import { DateTime } from 'luxon'
import ProductImage from './product_image.js'
export default class Product extends BaseModel {
@column({ isPrimary: true, serializeAs: null })
declare id: number
@column({ serializeAs: 'id' })
declare uuid: string
@column()
declare active: boolean
@column({ serializeAs: null })
declare clientId: number | null
@column()
declare sku: string
@column({ serializeAs: 'mainDescription' })
declare mainDescription: string
@column({ serializeAs: 'descLine1' })
declare descLine1: string | null
@column({ serializeAs: 'descLine2' })
declare descLine2: string | null
@column({ serializeAs: 'descLine3' })
declare descLine3: string | null
@column({ serializeAs: 'descLine4' })
declare descLine4: string | null
@column()
declare model: string
@column()
declare brand: string
@column()
declare departament: string
@column()
declare alcoholic: boolean
@column()
declare milk: boolean
@computed()
get mainImage() {
if (this.images && this.images.length) return this.images.find((image) => image.main)
return
}
@column.dateTime({ autoCreate: true, serializeAs: 'createdAt' })
declare createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true, serializeAs: 'updatedAt' })
declare updatedAt: DateTime
// Relationships
@hasMany(() => ProductImage)
declare images: HasMany<typeof ProductImage>
} migration:import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'product_images'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.uuid('uuid').unique().notNullable()
table.bigInteger('product_id').nullable()
table.boolean('main').notNullable()
table.string('description').nullable()
table.string('file_name').unique().notNullable()
table.timestamp('created_at', { useTz: true })
table.timestamp('updated_at', { useTz: true })
})
}
async down() {
this.schema.dropTable(this.tableName)
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
thetutlage
Feb 11, 2025
Replies: 1 comment 1 reply
-
Can you please enable query logging and see the queries being issues to the database? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
vandsonfalcao
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please enable query logging and see the queries being issues to the database?