开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜