code: private void matchJoinedFields(JoinInfo joinInfo, QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException {
  		for (FieldType fieldType : tableInfo.getFieldTypes()) {
  			// if this is a foreign field and its foreign field is the same as the other's id
  			FieldType foreignRefField = fieldType.getForeignRefField();
  			if (fieldType.isForeign() && foreignRefField.equals(joinedQueryBuilder.tableInfo.getIdField())) {
  				joinInfo.localField = fieldType;
  				joinInfo.remoteField = foreignRefField;
  				return;
  			}
  		}
  		// if this other field is a foreign field and its foreign-id field is our id
  		for (FieldType fieldType : joinedQueryBuilder.tableInfo.getFieldTypes()) {
  			if (fieldType.isForeign() && fieldType.getForeignIdField().equals(idField)) {
  				joinInfo.localField = idField;
  				joinInfo.remoteField = fieldType;
  				return;
  			}
  		}
  
  		throw new SQLException("Could not find a foreign " + tableInfo.getDataClass() + " field in "
  				+ joinedQueryBuilder.tableInfo.getDataClass() + " or vice versa");
  	}
docs: Match up our joined fields so we can throw a nice exception immediately if you can't join with this type.