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

[Bug]: AdminJs/Relations One to Many with TypeORM - TypeError: Cannot read properties of undefined (reading 'type') #1742

Open
plusalphanet opened this issue Feb 12, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@plusalphanet
Copy link

Contact Details

No response

What happened?

When setting up a OneToMany relationship in a typeorm environment, the following error occurs.

[Nest] 6208 - 2025. 02. 12. 오후 3:10:59 ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'type')
TypeError: Cannot read properties of undefined (reading 'type')
at Object.isParserForType (/Users/alpha/dev/nest-test/node_modules/@adminjs/typeorm/src/utils/filter/date-filter.parser.ts:5:78)
at (/Users/alpha/dev/nest-test/node_modules/@adminjs/typeorm/src/utils/filter/filter.converter.ts:17:42)
at Array.find ()
at (/Users/alpha/dev/nest-test/node_modules/@adminjs/typeorm/src/utils/filter/filter.converter.ts:17:28)
at Array.forEach ()
at convertFilter (/Users/alpha/dev/nest-test/node_modules/@adminjs/typeorm/src/utils/filter/filter.converter.ts:16:33)
at Resource.find (/Users/alpha/dev/nest-test/node_modules/@adminjs/typeorm/src/Resource.ts:67:14)
at oneToManyHandler (file:///Users/alpha/dev/nest-test/node_modules/@adminjs/relations/lib/actions/one-to-many/one-to-many.handler.js:1:607)
at file:///Users/alpha/dev/nest-test/node_modules/@adminjs/relations/lib/actions/relations.handler.js:1:727
at file:///Users/alpha/dev/nest-test/node_modules/adminjs/lib/backend/decorators/action/action-decorator.js:98:90
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

==================================

import { ApiProperty } from '@nestjs/swagger';
import {
BaseEntity,
Column,
Entity,
OneToMany,
PrimaryGeneratedColumn,
Relation,
} from 'typeorm';
import { ImageEntity } from './image.entity.js';

@entity({ name: 'user' })
export class UserEntity extends BaseEntity {
@ApiProperty()
@PrimaryGeneratedColumn()
user_id: number;

@ApiProperty()
@column()
user_name: string;

@ApiProperty()
@column()
email: string;

@onetomany(() => ImageEntity, (image) => image.owner)
images?: Relation[];
}

=========================

import { ApiProperty } from '@nestjs/swagger';
import {
BaseEntity,
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
Relation,
} from 'typeorm';
import { UserEntity } from './user.entity.js';

@entity({ name: 'photo_image' })
export class ImageEntity extends BaseEntity {
@ApiProperty()
@PrimaryGeneratedColumn()
image_id: number;

@manytoone(() => UserEntity, (user => user.images))
@joincolumn([{ name: 'owner_id' }])
owner: Relation;

@ApiProperty()
@column()
image_url: string;
}

================================

import { ResourceWithOptions } from 'adminjs';
import { owningRelationSettingsFeature, RelationType } from '@adminjs/relations';
import { UserEntity } from '../../users/entities/user.entity.js';
import { componentLoader } from '../componets.js';

const relationsLincenseKey = process.env.RELATIONS_LICENSE_KEY;

export const userResource: ResourceWithOptions = {
resource: UserEntity,
options: {
navigation: {
name: 'Users',
icon: 'Users',
},
},
features: [
owningRelationSettingsFeature({
componentLoader,
licenseKey: relationsLincenseKey,
relations: {
photo_images: {
type: RelationType.OneToMany,
target: {
resourceId: 'ImageEntity',
joinKey: 'owner_id',
},
},
},
}),
],
};

=====================================

import { ResourceWithOptions } from 'adminjs';
import { targetRelationSettingsFeature } from '@adminjs/relations';
import { ImageEntity } from '../../users/entities/image.entity.js';

export const imageResource: ResourceWithOptions = {
resource: ImageEntity,
options: {
id: 'ImageEntity',
navigation: {
name: 'Image',
icon: 'Image',
},
properties: {
image_url: {
isTitle: true,
},
},
sort: {
direction: 'asc',
sortBy: 'image_id',
},
},
features: [targetRelationSettingsFeature()],
};

Additionally, the phenomenon is the same even if the target > joinKey of owningRelationSettingsFeature is set to 'owner'.

Bug prevalence

Whenever

AdminJS dependencies version

"dependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.7",
"@types/passport-google-oauth20": "^2.0.16",
"@types/passport-local": "^1.0.38",
"@types/supertest": "^6.0.2",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2",
"globals": "^15.14.0",
"jest": "^29.7.0",
"prettier": "^3.4.2",
"punycode": "^2.3.1",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
},

What browsers do you see the problem on?

Chrome

Relevant log output

Relevant code that's giving you issues

@plusalphanet plusalphanet added the bug Something isn't working label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant