Criteriabuilder find a children property

24 views
Skip to first unread message

Tropicalista

unread,
May 1, 2016, 11:16:13 AM5/1/16
to ColdBox Platform
I have 2 entity ORM: Orders and Users with many to many relationship.

// M2M -> users
property name="users"
fieldtype="many-to-many" 
type="array" 
lazy="extra" 
cascade="none"
  cfc="user" 
  fkcolumn="FK_orderID" 
  linktable="userOrders" 
  notnull="false"
  inversejoincolumn="FK_userID";


// M2M -> orders
property name="orders"
fieldtype="many-to-many" 
type="array" 
lazy="extra" 
cascade="none"
  cfc="Ordine" 
  fkcolumn="FK_userID" 
  linktable="userOrders" 
  notnull="false"
  inversejoincolumn="FK_orderID";


I'm trying to use criteriabuilder to search a string in fields. 

var c = ORMService.newCriteria( "Order" );
var restrictions = [];


c.createAlias( "users", "u" )

arrayAppend(restrictions, c.restrictions.like( "this.Titolo", "%adm%" ));
arrayAppend(restrictions, c.restrictions.like( "u.username", "%adm%" ));
c.disjunction(restrictions);

var f = c
.withProjections( property="ordineID,Titolo,Descrizione,Data,Data_inizio,Data_completamento,u.username" )
.resultTransformer( c.ALIAS_TO_ENTITY_MAP )
.list();


The problem is with projection of many to many propery "u.username". If I remove that property from projections, query get executed correctly, but of course does not return the user.username field.

How can I solve this?

Thanks
:

Reply all
Reply to author
Forward
0 new messages