'Add joins for querying over test-related items.
These parameters are supported going forward:
* test_attribute_fields: list of attribute names.  Each attribute will
be available as a column attribute_<name>.value.
* test_label_fields: list of label names.  Each label will be available
as a column label_<name>.id, non-null iff the label is present.
* iteration_result_fields: list of iteration result names.  Each
result will be available as a column iteration_<name>.value.
Note that this changes the semantics to return iterations
instead of tests -- if a test has multiple iterations, a row
will be returned for each one.  The iteration index is also
available as iteration_<name>.iteration.
* machine_label_fields: list of machine label names.  Each will be
available as a column machine_label_<name>.id, non-null iff the
label is present on the machine used in the test.
* job_keyval_fields: list of job keyval names. Each value will be
available as a column job_keyval_<name>.id, non-null iff the
keyval is present in the AFE job.
* iteration_attribute_fields: list of iteration attribute names. Each
attribute will be available as a column
iteration_attribute<name>.id, non-null iff the attribute is
present.
These parameters are deprecated:
* include_labels
* exclude_labels
* include_attributes_where
* exclude_attributes_where
Additionally, this method adds joins if the following strings are
present in extra_where (this is also deprecated):
* test_labels
* test_attributes_host_labels'

def get_query_set_with_joins(self, filter_data):

    query_set = self.get_query_set()
    test_attributes = filter_data.pop('test_attribute_fields', [])
    for attribute in test_attributes:
        query_set = self._join_test_attribute(query_set, attribute)
    test_labels = filter_data.pop('test_label_fields', [])
    query_set = self._join_test_label_columns(query_set, test_labels)
    machine_labels = filter_data.pop('machine_label_fields', [])
    query_set = self._join_machine_label_columns(query_set, machine_labels)
    iteration_keys = filter_data.pop('iteration_result_fields', [])
    query_set = self._join_iteration_results(query_set, iteration_keys)
    job_keyvals = filter_data.pop('job_keyval_fields', [])
    query_set = self._join_job_keyvals(query_set, job_keyvals)
    iteration_attributes = filter_data.pop('iteration_attribute_fields', [])
    query_set = self._join_iteration_attributes(query_set, iteration_attributes)
    joined = False
    extra_where = filter_data.get('extra_where', '')
    if ('tko_test_labels' in extra_where):
        query_set = self._add_label_joins(query_set)
        joined = True
    include_labels = filter_data.pop('include_labels', [])
    exclude_labels = filter_data.pop('exclude_labels', [])
    if include_labels:
        query_set = self._include_or_exclude_labels(query_set, include_labels)
        joined = True
    if exclude_labels:
        query_set = self._include_or_exclude_labels(query_set, exclude_labels, exclude=True)
        joined = True
    include_attributes_where = filter_data.pop('include_attributes_where', '')
    exclude_attributes_where = filter_data.pop('exclude_attributes_where', '')
    if include_attributes_where:
        query_set = self._add_attribute_join(query_set, join_condition=self.escape_user_sql(include_attributes_where))
        joined = True
    if exclude_attributes_where:
        query_set = self._add_attribute_join(query_set, join_condition=self.escape_user_sql(exclude_attributes_where), exclude=True)
        joined = True
    if (not joined):
        filter_data['no_distinct'] = True
    if ('tko_test_attributes_host_labels' in extra_where):
        query_set = self._add_attribute_join(query_set, suffix='_host_labels', join_condition='tko_test_attributes_host_labels.attribute    =    "host-labels"')
    return query_set
