code: def restrict_joins(self, q, bindings):
          
          if len(q.froms) == 1:
              return q
          else:
              for binding in bindings:
                  if binding.table == self.fact_table:
                      continue
                  concept = self.model[binding.ref]
                  if isinstance(concept, Dimension):
                      dimension = concept
                  else:
                      dimension = concept.dimension
                  dimension_table, key_col = dimension.key_attribute.bind(self)
                  if binding.table != dimension_table:
                      raise BindingException('Attributes must be of same table as '
                                             'as their dimension key')
  
                  join_column_name = dimension.join_column_name
                  if isinstance(join_column_name, string_types):
                      try:
                          join_column = self.fact_table.columns[join_column_name]
                      except KeyError:
                          raise BindingException("Join column '%s' for %r not in fact table."
                                                 % (dimension.join_column_name, dimension))
                  else:
                      if not isinstance(join_column_name, list) or len(join_column_name) != 2:
                          raise BindingException("Join column '%s' for %r should be either a string or a 2-tuple."
                                                 % (join_column_name, dimension))
                      try:
                          join_column = self.fact_table.columns[join_column_name[0]]
                      except KeyError:
                          raise BindingException("Join column '%s' for %r not in fact table."
                                                 % (dimension.join_column_name[0], dimension))
                      try:
                          key_col = dimension_table.columns[join_column_name[1]]
                      except KeyError:
                          raise BindingException("Join column '%s' for %r not in dimension table."
                                                 % (dimension.join_column_name[1], dimension))
  
                  q = q.where(join_column == key_col)
          return q
docs: Restrict the joins across all tables referenced in the database
          query to those specified in the model for the relevant dimensions.
          If a single table is used for the query, no unnecessary joins are
          performed. If more than one table are referenced, this ensures
          their returned rows are connected via the fact table.