-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
ER_BAD_FIELD_ERROR: Unknown column 'treeEntity.parentId' in 'where clause #2361
Comments
I already asked you to format code properly. Please create a PR with a failing test which I can take a look (take a look how others do it). |
Already code mode but editor identification failed @pleerock |
It's my problem markdown unfamiliar |
it gets few minutes to get familiar with markdown. Please enable logging and show what schema queries typeorm executes for you |
|
please provide a schema creation part (drop all tables and re-run) |
|
I met the same issue on 'finRoots' call. The reason of this is that your Category entity has 'video_category_id' primary key instead of 'id'. Rename the 'video_category_id' to 'id' will fix the problem. It appears that TypeOrm in your case creates column as 'parentVideo_category_id' in category table. But during the call 'finRoots' tries to consume not existed 'parentId' (it is string concatenation 'parent'+'Id' but typeorm should use 'parent'+ 'Video_category_id' instead). So it is bug. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@pleerock Hi, I'm facing similar issue. I have custom naming strategy, so columns in DB are underscored naming-strategy.tsimport { DefaultNamingStrategy, NamingStrategyInterface } from "typeorm";
import { snakeCase } from "typeorm/util/StringUtils";
export class NamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
public tableName(targetName: string, userSpecifiedName: string): string {
return userSpecifiedName ? userSpecifiedName : snakeCase(targetName);
}
public columnName(propertyName: string, customName: string, embeddedPrefixes: Array<string>): string {
return snakeCase(embeddedPrefixes.concat(customName ? customName : propertyName).join("_"));
}
} Here's my entity: geo.tsimport { Column, CreateDateColumn, Entity, Index, JoinColumn, OneToMany, PrimaryGeneratedColumn, Tree, TreeChildren, TreeParent } from "typeorm";
@Entity({
name: "geo",
})
@Tree("materialized-path")
export class Geo {
@PrimaryGeneratedColumn("uuid")
public id: string;
@Column()
@Index({ unique: true })
public code: string;
@Column()
@Index({ unique: true })
public name: string;
@TreeParent()
public parent: Geo;
@TreeChildren()
public children: Array<Geo>;
@CreateDateColumn({
name: "created_at",
})
public createdAt: Date;
} So in my DB columns are underscored (i.e.
As you can see, the Is there some way to force It would be great, if we could specify in Which defined similar to this @TreeParent()
@JoinColumn({
name: "parent_id",
})
public parent: Geo; It's actually really critical to me so if you could help me I would be really thankful. |
@pleerock any thoughts on it? |
Just adding my +1 to this issue. Exactly the same problem as @LogansUA.
Although not as critical as I can rename the column, it would be nice to be able to keep column names consistent. |
Since there are multiple reports I'll mark it as a bug but we still need some tests before we fix it. |
Any updates on this? |
Create failing test for typeorm#2361 when id name in parent id different than id
@pleerock |
Updated test for typeorm#2361 with custom migrations
Fixes typeorm#2361. To be reviewed
Same issue! It deletes columns out of my database even with 'synchronize' off, not cool! |
Using an existing MySQL Database with custom fields too, would be great to be able to use custom field name, my query searches for field 'UserGuid' instead of just 'user'. |
@LogansUA
|
I think this is related to #1668 ? Difficult to tell. |
any updates on that? |
Here is another example of this not working (using SnakeNamingStrategy):
Which results in somewhat misleading |
any updates on that? I have simillar issue,,,
|
I can confirm this. E.g. I have a file const query = getRepository(CarDealer)
.createQueryBuilder('carDealer')
.delete()
.where('carDealer.id = :id', { id });
console.log(qb.getQueryAndParameters());
// [ 'DELETE FROM `car_dealer` WHERE carDealer.id = ?', [ 'xxxxxx' ] ]
// Leads to "QueryFailedError: Unknown column 'carDealer.id' in 'where clause'" However, it works fine when using single words (without dashs or snake case) as entities. It seems that the alias just gets ignored/not set in the query. |
I made a similar mistake:Unknown column 'treeEntity.id' in 'on clause' |
Had the same issue using TypeORM + NestJs, and ended that it was a problem of giving the params for the route itself. My "@param('id')" was without the 'id', so it was understanding it as an object, not as a numeric value.
|
I have the similar issue today and I solved it by changing @PrimaryColumn({ name: "user_id" })
- userId: number;
+ user_id: number; Also, since the product is already released, to avoid having to write a database migration, I also add the following line for the ancestor and descendant columns with the previous names from the database (something I should have done from the beginning). - @Tree("closure-table")
+ @Tree("closure-table", {
+ ancestorColumnName: () => "userId_ancestor",
+ descendantColumnName: () => "userId_descendant"
+ }) |
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:
Error:
The text was updated successfully, but these errors were encountered: