use of com.orm.androrm.field.OneToManyField in project androrm by androrm.
the class QueryBuilder method getRelationSelection.
@SuppressWarnings("unchecked")
private static final <T extends Model> SelectStatement getRelationSelection(Relation<?> r, Class<T> clazz, Rule rule) {
Class<? extends Model> target = r.getTarget();
Statement stmt = rule.getStatement();
Where where = new Where();
SelectStatement select = new SelectStatement();
if (r instanceof ManyToManyField) {
ManyToManyField<T, ?> m = (ManyToManyField<T, ?>) r;
stmt.setKey(DatabaseBuilder.getTableName(target));
where.setStatement(stmt);
select.from(m.getRelationTableName()).select(DatabaseBuilder.getTableName(clazz));
}
if (r instanceof OneToManyField) {
String backLinkFieldName = Model.getBackLinkFieldName(target, clazz);
stmt.setKey(backLinkFieldName);
where.setStatement(stmt);
select.from(DatabaseBuilder.getTableName(target)).select(backLinkFieldName + " AS " + DatabaseBuilder.getTableName(clazz));
}
select.where(where).distinct();
return select;
}
Aggregations