Get ActiveEntity as Query?

Maybe I’m missing this in the docs and digging through the API, but is there a built-in method to return the single active entity (using coldbox.system.orm.hibernate.ActiveEntity). Right now I’ve just created an ORM Decorator with the following method, but I’m converting a legacy app over and would rather not have to modify all of my views to use the getcolumn method.

`

/**

  • Returns the current instance of a single result as a query

**/

public function getRecordAsQuery(){

var n =“get”&this.getKey();

var s = structNew();

this.dynName = this[n];

s[this.getKey()]=this.dynName();

return this.list(criteria=s);

}

`

Thanks,
Jon

not that i know of.

you’ll prob have to stick w/ the decorator or base class.

or list(asquery=true,maxrows=1)[1];

I am confused, what are you trying to do?

i believe he wants to return a single entity as a query row.

And, yes, that code would less convoluted as:

`

public function getRateInfo(tourCode) output=“false” {
var tc= filterTourCode(arguments.tourcode);
var t = this.findbyTag(tc);
var r = t.getRates()[1];
return r.getRecordAsQuery();
}

`

:slight_smile:

Using findBy get’s you one only, use FindAllBy and that gives you an array

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

True. I’ve got that. What I was trying to do was to find a way to leverage the loaded one-to-many relationship iterators without having to call the findBy() function. So using this:

`

i.asQuery();

`

Rather than something like this:

`

i.findById(i.getId());

`

Which requires me to pass pass a double reference to the i variable - which seems somehow redundant to me.

I’m probably over-thinking this. I’ve been using PHP frameworks primarily for the last five years and, since the primary data container there is the array, almost all Active Record ORM methods have an “as_array()” equivalent that returns the instance record as named pair array. Thanks, Luis!

Every ORM method allows you to choose whether you want array or queries. We also have a query helper plugin that can help you slice the query up as you need, is that what you are looking for?

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Possibly. Perhaps I’m looking for the solution in wrong place. Let me dig in to the docs and see if maybe I missed the answer. In reference your response to the addAsset() question earlier, I hate it when I re-invent the wheel and, when learning a new framework, I’m always sure there’s a perfectly good method out there somewhere. :slight_smile: Thanks, again!