final int initialLength = sql.length();
final ObjectAdapter pattern = query.getPattern();
for (final ObjectAssociation assoc : specification.getAssociations()) {
final ObjectAdapter field = assoc.get(pattern);
if (field != null) {
final FieldMapping fieldMapping = fieldMappingFor(assoc);
if (fieldMapping != null) {
if (sql.length() > initialLength) {
sql.append(" AND ");
}
fieldMapping.appendWhereClause(connector, sql, pattern);
}
}
}
return loadInstances(connector, spec, completeSelectStatement(sql));
}