herbsjs / herbs2knex

Create repositories using Knex to retrieve and store Entities
Other
7 stars 13 forks source link

"Cannot read properties of undefined" error when entity has functions #73

Open vitorgamer58 opened 9 months ago

vitorgamer58 commented 9 months ago

Describe the bug When an entity has functions, a TypeError: Cannot read properties of undefined (reading 'isId') occurs.

I verified that this occurs in the getEntityIds function, as the entity fields are obtained through entity.prototype.meta.schema, but before filtering the id fields, you must go through this list again to filter the functions, as functions do not have the options field, resulting in an attempt to read the property of an undefined.

To Reproduce Create a project with Herbs2Knex, whose entity has functions, then try to run the project, making insertions and searches in the database.

Expected behavior The behavior is that this exception is not thrown.

Screenshots Screenshot_1600 Screenshot_1601

Additional context I believe this can be resolved by adding a .filter((field) => typeof field != 'function') in the idFields constant.