Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Undocumented (but hopefully allowed) extra use of DataSourceField.foreignKey

    Hi Isomorphic,

    as the docs don't mention it, I wanted to know if this use of DataSourceField.foreignKey is officially supported.

    I have a T_ADDRESS table, storing addresses for many different entities (users, resellers, leads, ...). Every row in that table has one and only one of the FKs set (via DB-CHECK-constraint). In each column (e.g. T_ADDRESS.RESELLER_ID), the values are unique (via DB-UNIQUE-constraint).

    The T_ADDRESS.ds.xml looks like this:
    Code:
    <DataSource dbName="Oracle" tableName="T_ADDRESS" ID="T_ADDRESS" serverType="sql">
    	<fields>
    		<field primaryKey="true" hidden="true" name="ID" type="sequence" />
    		.....
    		[B]<field foreignKey="T_RESELLER.ID" name="RESELLER_ID" type="integer" joinType="outer" relatedTableAlias="adr_res"/>
    		<field foreignKey="T_LEAD.ID" name="LEAD_ID" type="integer" joinType="outer" />[/B]
    		<field name="STREET" length="50" type="text" escapeHTML="true" required="true" />
    		.....
    	</fields>
    </DataSource>

    Another ds.xml (T_RESELLER.ds.xml) is this:
    Code:
    <DataSource dbName="Oracle" tableName="T_RESELLER" ID="T_RESELLER" serverType="sql">
    	<fields>
    		[B]<field primaryKey="true" hidden="true" name="ID" type="sequence" foreignKey="V_CURRENT_ACCOUNT_COUNT.RESELLER_ID" joinType="outer" />[/B]
    		.....
    		<field name="NAME" title="Resellername" length="60" type="text" escapeHTML="true" required="true">
    			<validators>
    				<validator type="isUnique"></validator>
    			</validators>
    		</field>
    	</fields>
    </DataSource>
    T_LEAD_ONLYRESELLER.ds.xml is this:
    Code:
    <DataSource dbName="Oracle" tableName="T_LEAD_ONLYRESELLER" ID="T_LEAD_ONLYRESELLER" serverType="sql">
    	<fields>
    		<field primaryKey="true" hidden="true" name="ID" type="sequence" />
    		<field hidden="true" name="TENANT_ID" type="integer" canEdit="false" />
    [B]		<field foreignKey="T_LEAD.ID" name="LEAD_ID" title="LEAD_ID" type="integer" />
    		<field foreignKey="T_RESELLER.ID" name="RESELLER_ID" title="Reseller" type="integer" displayField="RESELLER_NAME" />[/B]
    		<field name="RESELLER_NAME" [B]includeFrom="T_RESELLER.NAME"[/B] hidden="true" />
    		<field name="RESELLER_ZIPCODE" [B]includeFrom="[I][U]T_ADDRESS.ZIPCODE[/U][/I]" includeVia="RESELLER_ID"[/B] />
    		<field name="RESELLER_CITY" [B]includeFrom="[U][I]T_ADDRESS.CITY[/I][/U]" includeVia="RESELLER_ID"[/B] />
    		
    		<!-- TENANT_IDs for WHERE-clause generation -->
    		<field name="CREATED_BY_TENANT_ID" includeFrom="V_USER_CREATED_BY.TENANT_ID" hidden="true" />
    		<field name="MODIFIED_BY_TENANT_ID" includeFrom="V_USER_MODIFIED_BY.TENANT_ID" hidden="true" />
    		<field name="RESELLER_TENANT_ID" includeFrom="T_RESELLER.TENANT_ID" hidden="true" />
    		<field name="ADDRESS_TENANT_ID" [B]includeFrom="T_ADDRESS.TENANT_ID" includeVia="RESELLER_ID"[/B] hidden="true" />
    	</fields>
    </DataSource>
    Now if I assign a fetch to T_LEAD_ONLYRESELLER, following table clause is generated:
    Code:
        FROM t_lead_onlyreseller
             JOIN [B]t_reseller[/B] ON t_lead_onlyreseller.reseller_id = [B]t_reseller.id[/B]
             LEFT OUTER JOIN t_address a1 ON [B]t_reseller.id[/B] = a1.reseller_id
             JOIN v_user_created_by ON t_lead_onlyreseller.created_by = v_user_created_by.id
             JOIN v_user_modified_by ON t_lead_onlyreseller.modified_by = v_user_modified_by.id
    As you can see, the joins are generated correctly also backwards correctly - even over a middle T_RESELLER table. If this (which is GREAT) is intended, it would be good to include it in the docs.

    I also noted that I have to have the includeVia="RESELLER_ID" in the last table (T_LEAD_ONLYRESELLER),
    as there are two ways possible (the arrows being FKs)
    Code:
    T_LEAD_ONLYRESELLER -> T_LEAD <- T_ADDRESS
    T_LEAD_ONLYRESELLER -> T_RESELLER <- T_ADDRESS
    and the framework chooses the T_LEAD-way if I omit it.
    I also noted that relatedTableAlias="adr_res" (in T_ADDRESS) is not watched when generating the joins backwards.

    Best regards and thumbs up once again for the really impressive framework,
    Blama

    #2
    Yes, includeFrom is designed to automatically figure out indirect inclusions. But this is actually already covered in the docs:

    The inclusion can be indirect (traverse multiple DataSources) so long as there is a chain of <code>foreignKey</code> declarations from the target DataSource to the DataSource where the <code>includeFrom</code> field is declared.
    We're not sure what the issue is with relatedTableAlias, but note that this attribute is only active if includeVia is specified.

    Comment

    Working...
    X