code: def __init__(
      cls,
      classname: str,
      bases: Tuple[type, ...],
      dict_: Dict[str, Any],
      **kw: Any,
  ) -> None:
      # Only one of the base classes (or the current one) should be a table model
      # this allows FastAPI cloning a SQLModel for the response_model without
      # trying to create a new SQLAlchemy, for a new table, with the same name, that
      # triggers an error
      base_is_table = any(is_table_model_class(base) for base in bases)
      if is_table_model_class(cls) and not base_is_table:
          for (
              rel_name,
              rel_info,
          ) in cls.__sqlmodel_relationships__.items():
              if rel_info.sa_relationship:
                  # There's a SQLAlchemy relationship declared, that takes precedence
                  # over anything else, use that and continue with the next attribute
                  setattr(
                      cls, rel_name, rel_info.sa_relationship
                  )  # Fix #315
                  continue
              raw_ann = cls.__annotations__[rel_name]
              origin = get_origin(raw_ann)
              if origin is Mapped:
                  ann = raw_ann.__args__[0]
              else:
                  ann = raw_ann
                  # Plain forward references, for models not yet defined, are not
                  # handled well by SQLAlchemy without Mapped, so, wrap the
                  # annotations in Mapped here
                  cls.__annotations__[rel_name] = Mapped[ann]  # type: ignore[valid-type]
              relationship_to = get_relationship_to(
                  name=rel_name, rel_info=rel_info, annotation=ann
              )
              rel_kwargs: Dict[str, Any] = {}
              if rel_info.back_populates:
                  rel_kwargs["back_populates"] = rel_info.back_populates
              if rel_info.link_model:
                  ins = inspect(rel_info.link_model)
                  local_table = getattr(
                      ins, "local_table"
                  )  # noqa: B009
                  if local_table is None:
                      raise RuntimeError(
                          "Couldn't find the secondary table for "
                          f"model {rel_info.link_model}"
                      )
                  rel_kwargs["secondary"] = local_table
              rel_args: List[Any] = []
              if rel_info.sa_relationship_args:
                  rel_args.extend(rel_info.sa_relationship_args)
              if rel_info.sa_relationship_kwargs:
                  rel_kwargs.update(rel_info.sa_relationship_kwargs)
              rel_value = relationship(
                  relationship_to, *rel_args, **rel_kwargs
              )
              setattr(cls, rel_name, rel_value)  # Fix #315
          # SQLAlchemy no longer uses dict_
          # Ref: https://github.com/sqlalchemy/sqlalchemy/commit/428ea01f00a9cc7f85e435018565eb6da7af1b77
          # Tag: 1.4.36
          DeclarativeMeta.__init__(cls, classname, bases, dict_, **kw)
      else:
          ModelMetaclass.__init__(cls, classname, bases, dict_, **kw)
  
imports: import ipaddress
  import uuid
  import weakref
  from datetime import date, datetime, time, timedelta
  from decimal import Decimal
  from enum import Enum
  from pathlib import Path
  from typing import AbstractSet, Any, Callable, ClassVar, Dict, List, Mapping, Optional, Sequence, Set, Tuple, Type, TypeVar, Union, cast, overload
  from pydantic import BaseModel
  from pydantic.fields import FieldInfo
  from sqlalchemy import Boolean, Column, Date, DateTime, Float, ForeignKey, Integer, Interval, Numeric, inspect
  from sqlalchemy import Enum
  from sqlalchemy.orm import Mapped, RelationshipProperty, declared_attr, registry, relationship
  from sqlalchemy.orm.attributes import set_attribute
  from sqlalchemy.orm.decl_api import DeclarativeMeta
  from sqlalchemy.orm.instrumentation import is_instrumented
  from sqlalchemy.sql.schema import MetaData
  from sqlalchemy.sql.sqltypes import LargeBinary, Time
  from typing_extensions import Literal, deprecated, get_origin
  from ._compat import IS_PYDANTIC_V2, BaseConfig, ModelField, ModelMetaclass, Representation, SQLModelConfig, Undefined, UndefinedType, _calculate_keys, finish_init, get_annotations, get_config_value, get_field_metadata, get_model_fields, get_relationship_to, get_type_from_field, is_field_noneable, is_table_model_class, post_init_field_info, set_config_value, set_fields_set, sqlmodel_init, sqlmodel_validate
  from .sql.sqltypes import GUID, AutoString
label_desc: Use image node_id 4 to create a new SQLModelMetaclass object from inherited base classes: ModelMetaclass, DeclarativeMeta with example: obj = SQLModelMetaclass(cls, classname, bases, dict_)