Issue with Field Name Mapping in nestjs-graphql-tools
#36
-
IntroductionI'm using the Environment
ProblemWhen defining an entity with different field names in the code and the database, the query generated by Example Entity@ObjectType()
@Entity()
class Test {
@Field(() => Date)
@Column({name: "start_at"})
startAt: Date;
} IssueApplying a filter like Current workaround@ObjectType()
@Entity()
class Test {
@Field(() => Date)
@FilterField(() => Date, { sqlExp: 'test.start_at' })
@Column({name: "start_at"})
startAt: Date;
} This workaround involves hard-coding the entity name, which seems unsafe. QuestionIs there a better solution to ensure the correct field name (as defined in the database) is used in queries, without resorting to hard-coded values? Expected BehaviorThe nestjs-graphql-tools should automatically use the database field name (start_at in this case) in the generated queries when a filter is applied, without the need for custom filters or hard-coded values. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@dagyu Hello! I see your problem. At the current state it's the only way how you can do that. If you see any other way, feel free to open PR. |
Beta Was this translation helpful? Give feedback.
@dagyu Hello! I see your problem. At the current state it's the only way how you can do that. If you see any other way, feel free to open PR.
I would recommend not to use mappings like you do. Instead of specifying @column({name: "start_at"}), just use start_at instead of startAt.