Skip to content

Missing field rewrite OneToMany relation targets #1181

@christian-mibex

Description

@christian-mibex

Expected behavior

We migrated a while ago from the express-sequalize agent to the nodejs agent.
During that migration we wanted to keep the camelCase naming in the UI facing schema to avoid rework.
As suggested here we rename the fields and collections.

We expect the same behavior for added relations:

    licenses.addOneToManyRelation('comments', 'licenseComments', {
        originKey: 'license_id',
        originKeyTarget: 'license_name',
    })

Actual behavior

The schema generation fails with the following stack trace

TypeError: Cannot read properties of undefined (reading 'columnType')
    at Function.buildToManyRelationSchema (/node_modules/@forestadmin/agent/src/utils/forest-schema/generator-fields.ts:134:26)
    at Function.buildRelationSchema (/node_modules/@forestadmin/agent/src/utils/forest-schema/generator-fields.ts:229:38)
    at Function.buildSchema (/node_modules/@forestadmin/agent/src/utils/forest-schema/generator-fields.ts:44:40)
    at /node_modules/@forestadmin/agent/src/utils/forest-schema/generator-collection.ts:51:42
    at Array.map (<anonymous>)
    at Function.buildFields (/node_modules/@forestadmin/agent/src/utils/forest-schema/generator-collection.ts:51:8)
    at Function.buildSchema /node_modules/@forestadmin/agent/src/utils/forest-schema/generator-collection.ts:18:20)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

When I debug the code, I see that the relation in the schema generation code has the snake_case name for originKeyTarget which then results in an undefinded field and brakes the schema generation with the stack trace above.

{
  type: 'OneToMany',
  foreignCollection: 'licenseComments',
  originKey: 'licenseId',
  originKeyTarget: 'license_name'
}

Context

  • tested on latest releases

Metadata

Metadata

Assignees

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