问题
I'm currently trying to build a query that uses a datasource based on a particular condition being true. Say "if value == 1, use datasource 1. If value == 2, use datasource 2.
These tables are already a couple of levels into my datasources.
Haven't been able to find info on this anywhere!
回答1:
You did not specify the tables and relations, but using these datasources as an example:
- CustTable
- CustTrans (JoinMode: ExistsJoin)
- CustInvoiceJour (JoinMode: ExistsJoin)
Suppose you want to exists join on either CustTrans
or CustInvoiceJour
?
This can be accomplished by enabling and disabling the corresponding datasources:
custTable_ds.query().datasourceTable(tableNum(CustTrans)).enabled(!useInvoice);
custTable_ds.query().datasourceTable(tableNum(CustInvoiceJour )).enabled(useInvoice);
This should be done before super()
in the executeQuery
method of the CustTable
datasource.
来源:https://stackoverflow.com/questions/12256065/how-to-use-a-datasource-based-on-condition-being-true