view-entity with complex-alias

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

view-entity with complex-alias

Bob Morley
We ran into a situation where we wanted to model a view-entity that is the combination of a product and its good identification of type "SKU".  The trouble with the current set of alias elements is there does not appear to be a way to constraint it (or the join of the two entities) by column values.  During my hunting I found the follow comments in the entitymodel.xsd:

"In every SELECT statement, the fields that are normally used are really defined to be expressions.  
This means for example that you can supply an expression like (discountPercent * 100) in place of  just a field name.
The complex-alias tag is the Ofbiz way to do this."

This led me to believe that I may be able to create an alias in the view-entity that might be able to handle my requirement.  However, whenever I setup the complex-alias-field with a field that was not defined in the model, it would fail on start-up.  Nonetheless, believing that the code has changed since this comment was originally created, I made a slight modification to ModelViewEntity to allow fields that were not defined in the related entity model.  I then created the following "hack" ...

<alias entity-alias="PR" name="sku">
    <complex-alias operator="=" >
        <complex-alias-field entity-alias="PR" field="SELECT id_value FROM good_identification WHERE good_identification_type_id = 'SKU' AND product_id" />
        <complex-alias-field entity-alias="PR" field="productId" />
    </complex-alias>
</alias>

This resulted in producing sql for the view-entity that looks something like select x,y,(select z from t1 where ... ) ...

The short-sighted results looked good ... I am wondering if there is a better way to handle this type of requirement?  Do people typically revert to writing an ftl page rather then trying to utilize the view-entity in situations like this?  If this seems like some sort of reasonable approach do we feel there is value in productionizing it by extending the set of complex alias attributes so there is not hard-coded sql snippets?