Re: How to strip off selected columns from a criteria object

Thomas Vandahl <[email protected]> Thu, 06 May 2010 17:39:23 +0200
Newsgroups gmane.comp.jakarta.turbine.torque.user
Message-ID <[email protected]>
On 05.05.10 23:28, [email protected] wrote:
> Hi there,
> 
> I need to strip off all the selected columns (getSelectedColumns(), and
> getAsColumns()) from a criteria object, is there a way for me to do that?
> For examples:
> Criteria criteria = new Criteria();
> criteria.addJoin(PermissionPeer.PERMISSION_ID,RolePermissionPeer.PERMISSION_ID);
> criteria.addJoin(RolePermissionPeer.ROLE_ID, RolePeer.ROLE_ID);
> criteria.add(PermissionPeer.PERMISSION_ID, 1, Criteria.EQUAL)
> criteria.addSelectColumn(PermissionPeer.PERMISSION_ID);
> criteria.addAsColumn("permission", PermissionPeer.PERMISSION_ID);
> criteria.setDistinct();
> 
> where, I'd like to remove the selected columns:
> PermissionPeer.PERMISSION_ID,, but
> criteria.remove(PermissionPeer.PERMISSION_ID);
> doesn't do it for me.

Several databases require all columns used in the where-clause to be in
the list of selected columns, too. Furthermore, the Peer classes expect
all columns needed for the construction of the OM object to be present
in the result set. If you use BasePeer.doSelect, however, you can build
any criteria you want. You will get back Village records, though.

Bye, Thomas.