I have my domain class, with a named query:
class Atendimento implements Serializable {
...
Funcionario funcionario
static mapping = {
...
funcionario column: 'FUNCODIGO', sqlType: 'int'
}
static namedQueries = {
atendimentosPorData { data ->
data.clearTime();
eq('dataHora', data)
isNotNull('funcionario')
}
}
}
Application run on a legacy database with no FK constraints. The problem: there are some "broken" relationships, some "Atendimento" have a FUNCODIGO on the database, but there is no "Funcionario" with this identifier. I can query without problem, but when i send this to a view, like this
${fieldValue(bean: atendimentoInstance, field: "funcionario")}
I got a error saying that grails could not find "Funcionario" with id: xxxxx.
The isNotNUll on the criteria doesn't work because the column have data, but it fails when you try to resolve the join.
Is there a way to prevent the join on the "problematic" columns.
You can use ignoreNotFound to tell Grails ignore the missing references
Documentation
ignoreNotFound:
Specifies how foreign keys that reference missing rows are handled in many-to-one relationships.
class LegacyCdDomain {
String title
Thumbnail thumbnail
static mapping = {
thumbnail ignoreNotFound: true
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With