-
Hi, a bit new to nestjs and this library. I am having a rough time getting my relationships to be included in my gql query results. I have gone through the docs several times and it is not clear to me if assets.entity.ts @Entity({ name: 'assets' })
export class AssetEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ nullable: true, name: 'file_id' })
fileId: number;
@Column({ name: 'asset_name' })
assetName: string;
@ManyToOne(() => FileEntity, (fileEntity) => fileEntity.assets)
@JoinColumn({ name: 'file_id' })
file?: FileEntity;
@OneToMany(() => AssetCategoriesEntity, (entity) => entity.asset)
@JoinColumn({ name: 'asset_id' })
categories: AssetCategoriesEntity[];
} assets.model.ts @ObjectType('Asset', {
description: 'Asset model',
})
@UnPagedRelation('categories', () => AssetCategoriesModel, {
nullable: true,
})
@Relation('file', () => FileModel, {
nullable: true,
enableLookAhead: true,
})
@InputType()
export class AssetModel {
@IDField(() => Int)
id!: number;
@Field(() => Int, { nullable: true })
fileId: number;
@Field({ nullable: true })
assetName: string;
} asset-categories.entity.ts @Entity({ name: 'asset_categories' })
export class AssetCategoriesEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'asset_id' })
assetId: number;
@ManyToOne(
() => AssetEntity,
(entity) => entity.categories,
)
@JoinColumn([{ name: 'asset_id' }])
asset: AssetEntity;
} asset-categories.model.ts @ObjectType('AssetCategories', {
description: 'Asset Categories model',
})
export class AssetCategoriesModel {
@IDField(() => ID)
id!: number;
} I can see the query for the categories actually being used: SELECT DISTINCT `categories`.`id` AS `categories_id`, `categories`.`asset_id` AS `categories_asset_id` FROM `asset_categories` `categories` WHERE `categories`.`asset_id` IN (?) But nothing is returned:
Clearly I'm missing something; I'll happily provide more details if it would help. Should I be making custom dataloaders for these? I just wanted to clarify before going down that path. Any help is appreciated, even if it to point out something obvious I missed 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Everything looks ok, stupid questions:
And could you try removing the |
Beta Was this translation helpful? Give feedback.
Thanks for the repo, I have found the issue: The mapper expects all the types to be correct, your database is using
bigint
which causes therawRelations
to look like this:As you can see all the id's are now string, if we change the big int to integer the raw relations look like this:
Now all the id's are numbers, which is can than correctly be mapped back to the real entities values.
So, long story short, you can disable this behaviour by setting
bigNumberStrings
in your TypeORM conf…