Is this possible?
In the 3.1 beta documentation it seems possible:
Code:
<sql-query name="person">
<return alias="pers" class="Person"/>
<return-join alias="emp" property="pers.employments"/>
SELECT NAME AS {pers.*}, {emp.*}
FROM PERSON pers
LEFT OUTER JOIN EMPLOYMENT emp
ON pers.ID = emp.PERSON_ID
WHERE ID=?
</sql-query>
I've worked this into my own mapping with an example very similar to the above and have been playing with many different versions of it for the past few days. No matter what I do; however, I always get back an object array. What I really want is a fully initialized collection like one would get by doing a "fetch left join".
Another thing I think is a little odd is that as soon as I put in more joins, the debug output shows "lazy loading type select statements" for all collections, even though I've selected all the necessary data from the database in my native SQl qry. Can someone tell me if I'm on the wrong page with how this works?
Here are some examples of what I've been trying to do. Examples have been slimmed down to make them more clear
Code:
<class name = "Config" table="config">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<set name="selectBoxItems" lazy="false" fetch="join">
<key column="config_id"/>
<one-to-many class="DashSelectBoxItems"/>
</set>
<set name="data" lazy="false" fetch="join">
<key column="config_id"/>
<one-to-many class="Data"/>
</set>
<set name="notes" lazy="false" fetch="join">
<key column="config_id"/>
<one-to-many class="Notes"/>
</set>
<sql-query name="ConfigQuery">
<return alias="C" class="Config"/>
<return-join alias="ITEMS" property="C.selectBoxItems"/>
<return-join alias="DATA" property="C.data"/>
<return-join alias="NOTES" property="C.notes"/>
SELECT {C.*}, {ITEMS.*}, {DATA.*}, {NOTES.*}
FROM dash_config C LEFT OUTER JOIN dash_select_box_items ITEMS ON (C.id = ITEMS.config_id)
LEFT OUTER JOIN dash_tab_data DATA ON (C.id = DATA.config_id AND DATA.client_id = :CLIENT_ID)
LEFT OUTER JOIN dash_notes NOTES ON (C.id = NOTES.config_id AND NOTES.client_id = :CLIENT_ID)
ORDER BY C.tab_config_view_id, C.display_order, ITEMS.item
</sql-query>