def METHOD_NAME(self, data):
    """
    Validates if the provided data structure is correct and replaces the database
    and table references with selected instances. The following data format is
    expected:
    {
        "create": True,
        "read": [['database', ID], ['table', ID]],
        "update": False,
        "delete": True
    }
    which will be converted to:
    {
        "create": True,
        "read": [Database(ID), Table(ID)],
        "update": False,
        "delete": True
    }
    :param data: The non validated permissions containing references to the
        database and tables.
    :type data: dict
    :return: The validated permissions with objects instead of references.
    :rtype: dict
    """
    tables = {}
    databases = {}
    if not isinstance(data, dict) or len(data) != len(self.valid_types):
        self.fail("invalid_key")
    for key, value in data.items():
        if key not in self.valid_types:
            self.fail("invalid_key")
        if not isinstance(value, bool) and not isinstance(value, list):
            self.fail("invalid_value")
        if isinstance(value, list):
            for instance in value:
                if (
                    not isinstance(instance, list)
                    or not len(instance) == 2
                    or not isinstance(instance[0], str)
                    or not isinstance(instance[1], int)
                ):
                    self.fail("invalid_value")
                instance_type, instance_id = instance
                if instance_type == "database":
                    databases[instance_id] = None
                elif instance_type == "table":
                    tables[instance_id] = None
                else:
                    self.fail("invalid_instance_type")
    if len(tables) > 0:
        tables = {
            table.id: table
            for table in Table.objects.filter(id__in=tables.keys()).select_related(
                "database"
            )
        }
    if len(databases) > 0:
        databases = {
            database.id: database
            for database in Database.objects.filter(id__in=databases.keys())
        }
    for key, value in data.items():
        if isinstance(value, list):
            for index, (instance_type, instance_id) in enumerate(value):
                if instance_type == "database":
                    if instance_id not in databases:
                        self.fail("invalid_database_id", instance_id=instance_id)
                    data[key][index] = databases[instance_id]
                elif instance_type == "table":
                    if instance_id not in tables:
                        self.fail("invalid_table_id", instance_id=instance_id)
                    data[key][index] = tables[instance_id]
    return {
        "create": data["create"],
        "read": data["read"],
        "update": data["update"],
        "delete": data["delete"],
    }