# File sql-serialize.rb, line 732
  def sql_select_assocs (dbi)
    # this goes both for arrays and hashes

    ["array", "hash"].each { |range|
      sql = "SELECT * FROM " << sql_quote_name(self.type.name.sub(/#<Module .*?>::/, "") + "_" + range)
      sql << " WHERE " << sql_quote_name("sql_assoc_id") << " = "
      sql << sql_assoc_id(dbi).to_s << " ORDER BY " << sql_quote_name("symbol")

      # initialize

      if (range == "array")
        ary = Array.new
        keyname = "arr_index"
      else
        ary = Hash.new
        keyname = "key_id"
      end
      symbol = nil

      dbi.select_all(sql) { |row|
        # first iteration

        symbol = row["symbol"].dup if symbol.nil?
        symbol.untaint

        if (symbol == row["symbol"])
          # while we are still iteration through the same symbol,

          # load the object that id points to and add that to ary.

          # we make sure arrays aren't mixed via ORDER BY symbol.

          ary[row[keyname].to_i] = sql_select_from_id (dbi, row["val_id"])
        else
          # we are now done with one symbol and start on another

          # put the symbol into the object and clear the ary

          # then set symbol to the new symbol so we may start

          # loading the next range

          instance_eval("@" + symbol + " = ObjectSpace._id2ref(" << ary.id.to_s << ")")

          if (range == "array")
            ary = Array.new
            keyname = "arr_index"
          else
            ary = Hash.new
            keyname = "key_id"
          end
          symbol = row["symbol"].dup
          symbol.untaint
        end
      }
      # and just one last time to get the last range

      begin
        instance_eval("@" + symbol + " = ObjectSpace._id2ref(" << ary.id.to_s << ")")
      rescue TypeError
        # if the _array or _hash table is empty we will get a

        # an error here since symbol is nil. No worries, this is ok.

      end
    }

    # now the time has come for associated objects that are not arrays or hashes

    sql = "SELECT * FROM " << sql_quote_name(self.type.name.sub(/#<Module .*?>::/, "") + "_assoc")
    sql << " WHERE " << sql_quote_name("sql_assoc_id") << " = "
    sql << sql_assoc_id(dbi).to_s 

    dbi.select_all(sql) { |row|
      obj = sql_select_from_id(dbi, row["val_id"])
      symbol = row["symbol"].dup
      symbol.untaint
      instance_eval("@" + symbol + " = ObjectSpace._id2ref(" << obj.id.to_s << ")")
    }
  end