Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterInsert result fails to retrieve autogenerated datetime #2325

Open
anthonyma94 opened this issue Oct 13, 2022 · 0 comments
Open

afterInsert result fails to retrieve autogenerated datetime #2325

anthonyma94 opened this issue Oct 13, 2022 · 0 comments
Labels

Comments

@anthonyma94
Copy link

I'm using mariadb v10.4.25 with mysql2 drivers.

I have a class with an afterInsert hook as so:

CREATE TABLE `production_job_status` (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `job` varchar(30) NOT NULL,
  `assigned_to` varchar(255) DEFAULT NULL,
  `progress` int(2) DEFAULT 1,
  `order` int(3) DEFAULT NULL,
  `created_at` datetime(6) DEFAULT current_timestamp(6),
  `assigned_at` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
export default class ProductionJobStatus {
    id: number;
    job: string;
    assignedTo?: string;
    progress?: number;
    order?: number;
    assignedAt?: Dayjs;
    createdAt: Dayjs;
    static async afterInsert(args) {
        console.log(args.result[0].createdAt); // undefined
    }
}

args.result[0] will retrieve the newly inserted record, including the id, which is auto incremented. However, createdAt is nowhere to be found in the object. How can this be so?

@lehni lehni added the bug label Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants