gorm - How to create a custom Grails query -
i'm new grails , i've troubles queries. got 2 domain classes this:
class cliente { string nombre string cuit string localidad string establecimiento static hasmany = [facturas: factura] } class factura { string proveedor int sucursal string numero string letrafactura cliente cliente date fecha string tipo }
i want list elements in facturas
client name:
result expected:
proveedor|sucursal|numero|cliente_nombre|fecha
i've tried different ways cliente_id
not cliente_nombre
.
i think know asking: given client name, return list of factura
's, stipulation list of fields should contain client name rather client id.
import org.hibernate.criterion.criteriaspecification // given client name def clientnametosearch = 'some name' def crit = factura.createcriteria() def results = crit.list() { createalias('cliente', 'cli') eq('cli.nombre', clientnametosearch) // optional transformer output map rather list resulttransformer(criteriaspecification.alias_to_entity_map) projections { property('proveedor', 'proveedor') property('sucursal', 'sucursal') property('numero', 'numero') property('cli.nombre', 'clientenombre') property('fecha', 'fecha') } }
results
contain list of maps, each map having structure:
[ proveedor: ..., sucursal: ..., numero: ..., clientenombre: ..., fecha: ... ]
Comments
Post a Comment