lookinlab / adonis-lucid-soft-deletes

Addon for soft deletes AdonisJS Lucid ORM
MIT License
93 stars 7 forks source link

ER_BAD_FIELD_ERROR #5

Closed hunkaf closed 3 years ago

hunkaf commented 3 years ago

Hello, thanks for this great package. I've implemented according to your readme, and unfortunately got the below error, when trying to delete a user.

"update `users` set `updated_at` = '2021-08-19 09:27:52', `deleted_at` = 2021-08-19 09:27:52.239 +00:00 where `id` = 8 - ER_BAD_FIELD_ERROR: Unknown column '_zone' in 'field list'"

Could you please help me out with this? Thanks in advance!

My package.json:

{
  "name": "my-backend",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "node ace build --production",
    "start": "node server.js",
    "dev": "node ace serve --watch",
    "lint": "eslint . --ext=.ts",
    "format": "prettier --write ."
  },
  "devDependencies": {
    "@adonisjs/assembler": "^5.3.2",
    "adonis-preset-ts": "^2.1.0",
    "eslint": "^7.30.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-adonis": "^1.3.2",
    "eslint-plugin-prettier": "^3.4.0",
    "pino-pretty": "^5.1.1",
    "prettier": "^2.3.2",
    "typescript": "^4.2.4",
    "youch": "^2.2.2",
    "youch-terminal": "^1.1.1"
  },
  "dependencies": {
    "@adonisjs/core": "^5.1.9",
    "@adonisjs/lucid": "^15.0.3",
    "@adonisjs/repl": "^3.1.4",
    "adonis-lucid-filter": "^4.0.2",
    "adonis-lucid-soft-deletes": "^1.2.0",
    "luxon": "^2.0.1",
    "mysql": "^2.18.1",
    "phc-argon2": "^1.1.2",
    "proxy-addr": "^2.0.7",
    "reflect-metadata": "^0.1.13",
    "source-map-support": "^0.5.19"
  }
}

AdonisJS app is running in docker, if that matters.

LookinGit commented 3 years ago

Hi @hunkaf This error not due to a package. If you will update model without a package, an error get also. Somewhere in your code adding a field _zone to user, which no in a db table

Need the checking all "a path" before delete a user instance. It's all a can i help

hunkaf commented 3 years ago

Hi @LookinGit, thanks for your quick answer.

I've tried to change one line in your code: https://github.com/lookinlab/adonis-lucid-soft-deletes/blob/develop/src/SoftDeletes/index.ts#L113

Original:

      const softDelete = async (): Promise<void> => {
        this.deletedAt = DateTime.local()
        await this.save()
      }

Modified:

      const softDelete = async (): Promise<void> => {
        this.deletedAt = DateTime.local().toISO({ includeOffset: false })
        await this.save()
      }

Now it is working. Do you accept a PR for this change?

LookinGit commented 3 years ago

Thanks @hunkaf for this test. This is my bug Try add to your User model next code

@column.dateTime()
public deletedAt: DateTime | null

And write a result here. Fixed this code an error or no.

hunkaf commented 3 years ago

If add this, then working great :)

Maybe you could modify your code, when adding the column here: https://github.com/lookinlab/adonis-lucid-soft-deletes/blob/develop/src/SoftDeletes/index.ts#L29

The lucid datetime decorator adds a lot option here: https://github.com/adonisjs/lucid/blob/develop/src/Orm/Decorators/datetime.ts

LookinGit commented 3 years ago

@hunkaf thanks yep, i will fix this later in free time

LookinGit commented 3 years ago

Fixed c2630b