typeorm: ER_BAD_FIELD_ERROR: Unknown column 'treeEntity.parentId' in 'where clause

Issue type:

[ x ] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ x] mysql / mariadb [ ] oracle [ ] postgres [ ] sqlite [ ] sqljs [ ] react-native

TypeORM version:

[x ] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

url: documentation http://typeorm.io/#/tree-entities/working-with-tree-entities

code:


async videoCategoryList(): Promise<any> {
    const manager = getManager();

    const a1 = new Category();
    a1.name = "a1";
    await manager.save(a1);

    return await manager.getTreeRepository(Category).findRoots();
  }


@Entity()
@Tree('closure-table')
export class Category {

  @PrimaryGeneratedColumn('uuid', { comment: '唯一id' })
  video_category_id: string;

  @Column({ comment: '菜单名' })
  name: string;

  @Column({ type: 'enum', enum: ['0', '1'], comment: '视频分类,未定义的分类' })
  type: string;

  @TreeChildren()
  children: Category[];

  @TreeParent()
  parent: Category;

}

Error:


{
    "message": "ER_BAD_FIELD_ERROR: Unknown column 'treeEntity.parentId' in 'where clause'",
    "code": "ER_BAD_FIELD_ERROR",
    "errno": 1054,
    "sqlMessage": "Unknown column 'treeEntity.parentId' in 'where clause'",
    "sqlState": "42S22",
    "index": 0,
    "sql": "SELECT `treeEntity`.`video_category_id` AS `treeEntity_video_category_id`, `treeEntity`.`name` AS `treeEntity_name`, `treeEntity`.`type` AS `treeEntity_type`, `treeEntity`.`parentVideoCategoryId` AS `treeEntity_parentVideoCategoryId` FROM `category` `treeEntity` WHERE `treeEntity`.`parentId` IS NULL",
    "name": "QueryFailedError",
    "query": "SELECT `treeEntity`.`video_category_id` AS `treeEntity_video_category_id`, `treeEntity`.`name` AS `treeEntity_name`, `treeEntity`.`type` AS `treeEntity_type`, `treeEntity`.`parentVideoCategoryId` AS `treeEntity_parentVideoCategoryId` FROM `category` `treeEntity` WHERE `treeEntity`.`parentId` IS NULL"
}

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 25 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Any updates on this?

mature like milfs? 😆

@artem-hryb thanks for the confirmation, contributions are welcomed btw, we need to fix it if its a bug.

any updates on that?

@pleerock any thoughts on it?

@artem-hryb Thank you for your help . But I chose other more mature ORM Sequelize

any updates on that? I have simillar issue,

@Entity()
@Tree("closure-table", {
    closureTableName: "place",        
    ancestorColumnName: (column) => "ancestor_id",
    descendantColumnName: (column) => "descendant_id"
})
export class Place {
    
    @PrimaryGeneratedColumn()
    placeId: number;
    
    @TreeParent()     
    @JoinColumn({name : "parent_id"})
    parent: Place;   

    @TreeChildren()
    children: Place[];
}
async findOneRootTreeWithTagValues(place){        
        const manager = await getManager();
        const trees = await manager.getTreeRepository(Place).findDescendantsTree(place)
}
QueryFailedError: ER_BAD_FIELD_ERROR: Unknown column 'treeEntity.placeId' in 'on clause'

@LogansUA add code below to your naming-strategy.ts

joinColumnName(relationName: string, referencedColumnName: string): string {
    return snakeCase(relationName + '_' + referencedColumnName);
}

@pleerock I created failing test for this issue, and I can also try to fix this issue. Do you have any decorator you would prefer to modify in order to add this custom id name?

Since there are multiple reports I’ll mark it as a bug but we still need some tests before we fix it.