Skip to content

Issue when using ts-mixer with Objection.js #2150

@nickyang07

Description

@nickyang07

Hi:

I recently notice when I use ts-mixer (https://www.npmjs.com/package/ts-mixer) to construct the Model with a trait, eg:

class ModelBase extends Model {...}
class ModelTrait {...}
class User extends Mixin(ModelBase, ModelTrait) {...}

this line will throw error: https://github.com/Vincit/objection.js/blob/master/lib/model/Model.js#L866. The reason is because for Mixin, somehow the modelType.prototype can be undefined in this case, which throws 'Cannot convert null or undefined to object' error.

An easy fix is to add one check here (https://github.com/Vincit/objection.js/blob/master/lib/model/Model.js#L861) so we have:

if (modelClass === Model || modelClass.prototype == undefined) {
    // Stop recursion to the model class or its prototype is null or undefined
    return [];
  }

Is this a reasonable ask?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions