private void matchJoinedFields(QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException {
		for (FieldType fieldType : tableInfo.getFieldTypes()) {
			// if this is a foreign field and its foreign-id field is the same as the other's id
			FieldType foreignIdField = fieldType.getForeignIdField();
			if (fieldType.isForeign() && foreignIdField == joinedQueryBuilder.tableInfo.getIdField()) {
				localJoinedField = fieldType;
				remoteJoinedField = foreignIdField;
				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() == idField) {
				localJoinedField = idField;
				remoteJoinedField = fieldType;
				return;
			}
		}

		throw new SQLException("Could not find a foreign " + tableInfo.getDataClass() + " field in "
				+ joinedQueryBuilder.tableInfo.getDataClass() + " or vice versa");
	}