1

I'm trying here before going to create an issue as it might be simply my comprehension of how to use filters in LB4.

I'm using postgresql as a database within a lb4 application. I made my controller, my models, and added the logic. I want my models to give back some relation in the response, so I created a default filter that will be used in a controller and repository :

const includedRelations = {
  include: [
    {
      relation: "licenseeloans",
      scope: {
        include: [
          {
            relation: "member"
          }
        ]
      }
    },
    {
      relation: "weaponloans"
    },
    {
      relation: "initiator"
    },
    {
      relation: "returnInitiator"
    }
  ]
}

And here is the controller part :

  console.log(includedRelations.include[0].scope)
  const newLoanWithRelation = await this.loanRepository.findById(newLoan.id, includedRelations);
  console.log(includedRelations.include[0].scope)

I found out that using this method give me this result:

{ include: [ { relation: 'member' } ] }
{ include: [ { relation: 'member' } ],
  where: { id: '42177991-308b-488c-b9d5-f50496d08281' } }

And next iteration :

{ include: [ { relation: 'member' } ],
  where: { and: [ [Object], [Object] ] } }

Is it a normal behavior that using the findById with a filter modify the filter object (by getting populated ?)or is it a bug? What should be my best options, cloning the inclusion filter everytime I want to get an object from the repository with relations ? I ran into this because after few request, my filter was too deep and loopback4 was throwing "QUERY_OBJECT_TOO_DEEP" errors.

Note: I didn't checked for other methods such as find and findOne.

Thanks for the help :) !

Sami Tahri
  • 1,077
  • 9
  • 19

1 Answers1

2

This was a known bug, and has been fixed in @loopback/repository@3.4.0.

Rifa Achrinza
  • 1,555
  • 9
  • 19
  • Yep, I'm the creator of the issue (+multiple other has been related I guess) and it was fixes, thanks to the team :) ! – Sami Tahri Jan 31 '21 at 19:46