mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-20 06:00:44 +00:00
Add overload of getForeignRecordMap that takes additional (base) filter for query
This commit is contained in:
@ -67,6 +67,21 @@ public class GeneralProcessUtils
|
||||
** via getForeignRecordMap(input, orderList, "clientId", "client", "id")
|
||||
*******************************************************************************/
|
||||
public static Map<Serializable, QRecord> getForeignRecordMap(AbstractActionInput parentActionInput, List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName) throws QException
|
||||
{
|
||||
return getForeignRecordMap(parentActionInput, sourceRecords, sourceTableForeignKeyFieldName, foreignTableName, foreignTablePrimaryKeyName, new QQueryFilter());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** For a list of sourceRecords,
|
||||
** lookup records in the foreignTableName,
|
||||
** that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords.
|
||||
**
|
||||
** e.g., for a list of orders (with a clientId field), build a map of client.id => client record
|
||||
** via getForeignRecordMap(input, orderList, "clientId", "client", "id")
|
||||
*******************************************************************************/
|
||||
public static Map<Serializable, QRecord> getForeignRecordMap(AbstractActionInput parentActionInput, List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName, QQueryFilter additionalFilter) throws QException
|
||||
{
|
||||
Map<Serializable, QRecord> foreignRecordMap = new HashMap<>();
|
||||
QueryInput queryInput = new QueryInput(parentActionInput.getInstance());
|
||||
@ -74,7 +89,9 @@ public class GeneralProcessUtils
|
||||
queryInput.setTableName(foreignTableName);
|
||||
List<Serializable> foreignIds = new ArrayList<>(sourceRecords.stream().map(r -> r.getValue(sourceTableForeignKeyFieldName)).toList());
|
||||
|
||||
queryInput.setFilter(new QQueryFilter().withCriteria(new QFilterCriteria(foreignTablePrimaryKeyName, QCriteriaOperator.IN, foreignIds)));
|
||||
additionalFilter.addCriteria(new QFilterCriteria(foreignTablePrimaryKeyName, QCriteriaOperator.IN, foreignIds));
|
||||
queryInput.setFilter(additionalFilter);
|
||||
|
||||
QueryOutput queryOutput = new QueryAction().execute(queryInput);
|
||||
for(QRecord foreignRecord : queryOutput.getRecords())
|
||||
{
|
||||
|
Reference in New Issue
Block a user