Where should CF ORM functions relating to multiple instances belong?
I want to concatenate the values of two columns into one when retrieving all instances of a model. I am unsure where this function should be located though.
If I place it in the model it can only be called on a specific instance, and it relates to all instances so that isn't correct.
Or is there a better 开发者_C百科way of retrieving the data? It will be used in a form select box.
...
<cfquery name="products" datasource="#########">
SELECT (brand + ' ' + name) AS [product], id
FROM products
</cfquery>
...
multiple instances as in multiple products in this case.
Like Dave, I don't understand your references to "instances", but here is what I do with CF ORM if I need two fields concatenated into a commonly used value -- I'd add this function to the definition CFC itself.
/**
* products
* @output false
* @persistent true
*/
component
{
property name="id" fieldtype="id";
property name="name";
property name="brand";
// concatenate fields to make Product
public string function getProduct() {
return variables.brand & " " & variables.name;
}
}
Then after retrieving the entity, call getID() and getProduct() for the 2 fields you use.
精彩评论