adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.02k stars 189 forks source link

Clone method removes preloads #1033

Open enixsoft opened 4 weeks ago

enixsoft commented 4 weeks ago

Package version

├── @adonisjs/assembler@7.6.1 ├── @adonisjs/core@6.9.0 ├── @adonisjs/eslint-config@1.3.0 ├── @adonisjs/lucid@20.6.0 ├── @adonisjs/prettier-config@1.3.0 ├── @adonisjs/tsconfig@1.3.0 ├── @japa/assert@3.0.0 ├── @japa/plugin-adonisjs@3.0.1 ├── @japa/runner@3.1.4 ├── @swc/core@1.5.24 ├── @types/luxon@3.4.2 ├── @types/node@20.12.13 ├── eslint@8.57.0 ├── hot-hook@0.2.6 ├── luxon@3.4.4 ├── pg@8.11.5 ├── pino-pretty@11.1.0 ├── prettier@3.2.5 ├── reflect-metadata@0.2.2 ├── ts-node@10.9.2 └── typescript@5.4.5

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"
     }
  ]
}
MaximeMRF commented 2 weeks ago

I have the same problem

RomainLanz commented 1 week ago

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