Skip to content

[BUG] Output DTO predicate '!where(fkPropertyName is not null)'在Kotlin下没有正确导入扩展方法,因此在编译时产生类型不匹配报错 #915

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

Closed
pot-mot opened this issue Feb 10, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@pot-mot
Copy link
Contributor

pot-mot commented Feb 10, 2025

Jimmer Version

0.9.49

JDK Version

JDK21

Database

PostgreSQL

OS

Windows

当我使用了 !where(fkPropertyName is not null),isNotNull() 扩展函数出现类型不匹配错误:

filter {
  where(
      table.fkPropertyName.isNotNull()
  )
}
<html>Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:<br/>public fun KExpression&lt;*&gt;.isNotNull(): KNonNullExpression&lt;Boolean&gt; defined in org.babyfish.jimmer.sql.kt.ast.expression

由于此时 is null 判断的是外键属性,正确的导入应该是 table 包下的:

import org.babyfish.jimmer.sql.kt.ast.table.isNotNull

此时导入的 isNotNull 是 expression 包下的:

org.babyfish.jimmer.sql.kt.ast.expression.isNotNull
@pot-mot pot-mot added the bug Something isn't working label Feb 10, 2025
@pot-mot pot-mot changed the title [BUG] Output DTO predicate '!where(propertyName is not null)'在Kotlin下没有正确导入扩展方法,因此在编译时产生类型不匹配报错 [BUG] Output DTO predicate '!where(fkPropertyName is not null)'在Kotlin下没有正确导入扩展方法,因此在编译时产生类型不匹配报错 Feb 10, 2025
@pot-mot
Copy link
Contributor Author

pot-mot commented Feb 10, 2025

需要在 DtoGenerator CodeBlock.Builder.addPredicate 中添加一个判断,大概是:

if (// if predicate is a single reference) {
    if (predicate.isNegative) {
        add(".%M()", MemberName(TABLE_PACKAGE, "isNotNull"))
    } else {
        add(".%M()", MemberName(TABLE_PACKAGE, "isNull"))
    }
} else {
    if (predicate.isNegative) {
        add(".%M()", MemberName(EXPRESSION_PACKAGE, "isNotNull"))
    } else {
        add(".%M()", MemberName(EXPRESSION_PACKAGE, "isNull"))
    }
}

@pot-mot
Copy link
Contributor Author

pot-mot commented Feb 10, 2025

目前可以先用 idView 绕过去

babyfish-ct added a commit that referenced this issue Feb 10, 2025
babyfish-ct added a commit that referenced this issue Feb 10, 2025
@babyfish-ct
Copy link
Owner

Try 0.9.50

If you use parent, it will tell you to use parentId even if there is no @idview property

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

2 participants