Open
Description
In fflib_SObjectSelector
we have a useful method to add lookup fields from a selector instance to an existing queryFactory
public void configureQueryFactoryFields(fflib_QueryFactory queryFactory, String relationshipFieldPath)
{
// Add fields from selector prefixing the relationship path
for(SObjectField field : getSObjectFieldList())
queryFactory.selectField(relationshipFieldPath + '.' + field.getDescribe().getName());
// Automatically select the CurrencyIsoCode for MC orgs (unless the object is a known exception to the rule)
if(Userinfo.isMultiCurrencyOrganization() && CURRENCY_ISO_CODE_ENABLED)
queryFactory.selectField(relationshipFieldPath+'.CurrencyIsoCode');
}
Use case from Force.com Enterprise Architecture second edition p 228 is
fflib_QueryFactory contestantFactory = newQueryFactory();
new DriversSelector()
.configureQueryFactoryFields(contestantFactory,'Driver__r');
return Database.query(contestantFactory.setCondition(...).toSOQL());
Seems like it would be useful (at least to me) to be able to configure the parent lookup fields via a fieldset as in:
fflib_QueryFactory contestantFactory = newQueryFactory();
new DriversSelector()
.configureQueryFactoryFields(contestantFactory,
'Driver__r',SObjectType.Driver.fieldsets.MyFieldSet);
return Database.query(contestantFactory.setCondition(...).toSOQL());
where the code for this in fflib_SObjectSelector would be something like this:
/**
* adds a specific fieldset to a given relationship (lookup) as a prefix
*/
public void configureQueryFactoryFields(fflib_QueryFactory queryFactory, String relationshipFieldPath, Schema.FieldSet fieldSet) {
// Add fields from fieldSet to queryFactory prepended by relationshipFieldPath
if (fieldSet.getSObjectType() != getSObjectType()) {
throw new fflib_QueryFactory.InvalidFieldSetException('Field set "' + fieldSet.getName() +
'" is not for SObjectType ' + getSObjectType());
}
for (Schema.FieldSetMember field: fieldSet.getFields()) {
queryFactory.selectField(relationshipFieldPath + '.' + field.getFieldPath());
}
if(Userinfo.isMultiCurrencyOrganization() && CURRENCY_ISO_CODE_ENABLED) {
queryFactory.selectField(relationshipFieldPath+'.CurrencyIsoCode');
}
}
Or is there some existing way to do this that I have overlooked (configuring a queryfactory's lookup fields via a fieldset of the parent Sobject?