[coldbox-3.8.1] ORM Dynamic Finders & Property Names Containing "and/or"

51 views
Skip to first unread message

Wesley Hampton

unread,
Sep 26, 2014, 12:28:56 PM9/26/14
to col...@googlegroups.com
This might be documented somewhere but I ran across a problem today when trying to use the Dynamic Finders with a property named Port which contained the substring "or" in it.  The message received was:

The property you requested P is not a valid property in the Nifty entity

My line of code was called from a handler was:
niftyService.findByPort(port).getID();


Apparently if you have entity properties that contain the substring "or" or "and" then the dynamic finder thinks you are specifying additional criteria.

Is there a way to get around this while still using Dynamic Finders?

I just ended up creating an actual niftyService.cfc and using Criteria Builder instead...but hoping there is a better way?

niftyService.cfc
component extends="coldbox.system.orm.hibernate.VirtualEntityService" singleton {

   
// Dependency Injection
    property name
="niftyService" inject="entityService:Nifty";

   
/**
    * Constructor
    */

   
public NiftyService function init(){
       
super.init(entityName="Nifty");
       
return this;
   
}

   
/**
    * Returns a Nifty object based on the Port provided
    */

    any
function getNiftyByPort(port) {

       
var c = niftyService.newCriteria();
       
var nifty = c.eq("port", c.convertValueToJavaType( propertyName="port", value=port )).get();

       
return nifty;
   
}

}

New call from the handler:
niftyService.getNiftyByPort(port).getID();

Andrew Scott

unread,
Sep 26, 2014, 12:38:24 PM9/26/14
to col...@googlegroups.com
Should this

niftyService.findByPort(port).getID();

be

niftyService.findByPort("port").getID();


Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wesley Hampton

unread,
Sep 26, 2014, 12:55:09 PM9/26/14
to col...@googlegroups.com
Hey thanks for the reply, Andrew.  I should have been more clear.

I was calling it like this:
var port = 8080;
niftyService
.findByPort(port).getID();

But the problem appears to be where I highlighted in yellow above.

Probably also likely to fail:
findByHandle(a);
findBySp
ort(b);
findByH
andleAndSportAndName(a,b,c);

Andrew Scott

unread,
Sep 26, 2014, 1:02:57 PM9/26/14
to col...@googlegroups.com
Ok, yeah that is what you get when you try to anticipate things like

findByXXXXorYYYYandFFFF()



Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


br...@bradwood.com

unread,
Sep 26, 2014, 2:13:21 PM9/26/14
to col...@googlegroups.com
I've never looked at that code, but it seems like there's no reason not to be able to work around that.  If the string is parsed from left to right and the code looks for full property names first starting with the longest to the shortest property name, THEN looks for a keyword like and/or then it should fix that.
 
Who wants to do a pull request!?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
This might be documented somewhere but I ran across a problem today when trying to use the Dynamic Finders with a property named Portwhich contained the substring "or" in it.  The message received was:

Don Q

unread,
Nov 18, 2014, 2:47:14 PM11/18/14
to col...@googlegroups.com
This should now be fixed on the development branch of the cborm module.  https://github.com/ColdBox/cbox-cborm/pull/4#event-195086312

Wesley Hampton

unread,
Aug 24, 2015, 4:35:54 PM8/24/15
to ColdBox Platform
Still having some problems with this now that I switched to the cborm module in CB4 (though I doubt it's due specifically to that, I just haven't tested this functionality in a while)

Opened an issue in cbox-cborm, probably an easy fix on the RegEx but I haven't been able to dig it out yet.

Thanks!
Reply all
Reply to author
Forward
0 new messages