Problemas com relacionamento hasOne
27/09/2013 23:06
class Entregas {
static hasMany = [pedidos:Pedidos]
static hasOne = [endereco:Enderecos]
Funcionario funcionario
Cliente cliente
EstadoEntregaEnum situacaoEntrega
Date dtEntrega
Date dtSolicitacao
double total = 0
static constraints = {
funcionario nullable:false
dtEntrega nullable:true
dtSolicitacao nullable:true
cliente nullable:true
situacaoEntrega nullable:false
}
class Cliente extends Pessoas{
static hasMany = [entregas:Entregas]
String email
static constraints = {
email nullable:false
}
}
abstract class Pessoas {
String nome
String sobrenome
String celular
Enderecos endereco
static constraints = {
nome blank:false, nullable:false, size:3..30
sobrenome blank:false, nullable:false, size:3..30
celular blank:false
endereco nullable:true
}
}
class Enderecos {
static belongsTo= [entrega:Entregas, pessoa:Pessoas]
String cidade
EstadoEnum estado
String bairro
String rua
String complemento
String referencia
String cep
Float latitude = null
Float longitude = null
static constraints = {
cidade blank:false, nullable:false
estado blank:false, nullable:false
bairro blank:false, nullable:false
rua blank:false, nullable:false
cep blank:false, nullable:false
latitude blank:true, nullable:true
longitude blank:true, nullable:true
entrega(nullable: true, validator: {field, inst -> inst.pessoa || field})
pessoa(nullable: true)
}
}
entrega(nullable: true, validator: {field, inst -> inst.pessoa || field})
pessoa(nullable: true, validator: {field, inst -> inst.entrega || field})
entrega(nullable: true, validator: {field, inst -> inst.pessoa || field})
pessoa(nullable: true, validator: {field, inst -> inst.entrega || field})
entrega (nullable: true, validator: {val, obj-> if (!val && !obj.pessoa) return 'modelo.nao.associado'})
pessoa (nullable: true, validator: {val, obj-> if (!val && !obj.entrega) return 'modelo.nao.associado'})
entrega (nullable: true, validator: {val, obj-> if ((val==null) && (obj.pessoa==null)) return 'modelo.nao.associado'})
pessoa (nullable: true, validator: {val, obj-> if ((val==null) && (obj.entrega==null)) return 'modelo.nao.associado'})
Para se registrar, clique aqui.