lucid icon indicating copy to clipboard operation
lucid copied to clipboard

Clone method removes preloads

Open enixsoft opened this issue 1 year ago • 2 comments

Package version

├── @adonisjs/[email protected] ├── @adonisjs/[email protected] ├── @adonisjs/[email protected] ├── @adonisjs/[email protected] ├── @adonisjs/[email protected] ├── @adonisjs/[email protected] ├── @japa/[email protected] ├── @japa/[email protected] ├── @japa/[email protected] ├── @swc/[email protected] ├── @types/[email protected] ├── @types/[email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]

Describe the bug

Hello. I have found a possible bug when using clone() method on ModelQueryBuilderContract which has a preload. The cloned query will not execute the preload query. I am using PostgreSQL 15.1 database.

const postQuery = Post.query().preload('user')

const clonedPostQuery = postQuery.clone()

return { post: await postQuery, clonedPost: await clonedPostQuery }

The result is:

{
  "post":[
     {
        "id":1,
        "userId":1,
        "title":"Test",
        "createdAt":"2024-05-30T14:11:18.505+00:00",
        "updatedAt":"2024-05-30T14:11:18.505+00:00",
        "user":{
           "id":1,
           "name":"Test",
           "createdAt":"2024-05-30T14:11:08.784+00:00",
           "updatedAt":"2024-05-30T14:11:08.784+00:00"
        }
     }
  ],
  "clonedPost":[
     {
        "id":1,
        "userId":1,
        "title":"Test",
        "createdAt":"2024-05-30T14:11:18.505+00:00",
        "updatedAt":"2024-05-30T14:11:18.505+00:00"
     }
  ]
}

enixsoft avatar May 30 '24 14:05 enixsoft

I have the same problem

MaximeMRF avatar Jun 14 '24 08:06 MaximeMRF

Could you please create a pull request with a failing test?

RomainLanz avatar Jun 17 '24 07:06 RomainLanz

@RomainLanz added

aadamcik avatar Jul 08 '24 14:07 aadamcik