0

Hi I would like to do something like this -

  where: {id : id},
  relations: {
      photos: true
  },
  photos: {
    take: 10,
    skip: 5
  }

I want to add take and skip inside relations. Do you have a suggestion? Thank you.

1 Answers1

0

maybe you can take a look at this code:

async findSomethings(ids, page, limit) {
   aRepository.find({
      where: {
          id: In(ids)
      },
      relations: ["photos"],
      take: limit,
      skip: (page - 1) * limit,
   })
}

for reference maybe you can see more detaiils in typeorm documentation https://typeorm.io/find-options, thank you

  • I want to add take and skip inside relationship. – Thiha Kyaw Aug 05 '22 at 02:03
  • if you want take and skip inside relationship, maybe you can do pagination manually for "photos", because photos is an array you can do pagination like this `array.slice((page_number - 1) * page_size, page_number * page_size)`, for more details you can check this link https://stackoverflow.com/questions/42761068/paginate-javascript-array, or you can do typeorm paginate "photos" by id of the "parent" like ("user") – Rodericus Ifo Krista Aug 05 '22 at 02:31