code: def test_declaredattr(app: Flask, model_class: t.Any) -> None:
      if model_class is Model:
  
          class IdModel(Model):
              @sa.orm.declared_attr
              @classmethod
              def id(cls: type[Model]):  # type: ignore[no-untyped-def]
                  for base in cls.__mro__[1:-1]:
                      if getattr(
                          base, "__table__", None
                      ) is not None and hasattr(base, "id"):
                          return sa.Column(
                              sa.ForeignKey(base.id), primary_key=True
                          )
                  return sa.Column(sa.Integer, primary_key=True)
  
          db = SQLAlchemy(app, model_class=IdModel)
  
          class User(db.Model):
              name = db.Column(db.String)
  
          class Employee(User):
              title = db.Column(db.String)
  
      else:
  
          class Base(sa_orm.DeclarativeBase):
              @sa_orm.declared_attr
              @classmethod
              def id(
                  cls: type[sa_orm.DeclarativeBase],
              ) -> sa_orm.Mapped[int]:
                  for base in cls.__mro__[1:-1]:
                      if getattr(
                          base, "__table__", None
                      ) is not None and hasattr(base, "id"):
                          return sa_orm.mapped_column(
                              db.ForeignKey(base.id), primary_key=True
                          )
                  return sa_orm.mapped_column(
                      db.Integer, primary_key=True
                  )
  
          db = SQLAlchemy(app, model_class=Base)
  
          class User(db.Model):  # type: ignore[no-redef]
              name: sa_orm.Mapped[str] = sa_orm.mapped_column(db.String)
  
          class Employee(User):  # type: ignore[no-redef]
              title: sa_orm.Mapped[str] = sa_orm.mapped_column(
                  db.String
              )
  
      db.create_all()
      db.session.add(Employee(name="Emp Loyee", title="Admin"))
      db.session.commit()
      user = db.session.execute(db.select(User)).scalar()
      employee = db.session.execute(db.select(Employee)).scalar()
      assert user is not None
      assert employee is not None
      assert user.id == 1
      assert employee.id == 1
  
imports: from __future__ import annotations
  import typing
  from datetime import datetime
  import pytest
  import sqlalchemy
  import sqlalchemy.exc
  import sqlalchemy.orm
  from flask import Flask
  from flask_sqlalchemy import SQLAlchemy
  from flask_sqlalchemy.model import DefaultMeta
  from flask_sqlalchemy.model import Model
label_desc: Use image node_id 8 for calling a global function with example usage: test_declaredattr(app, model_class) and returns: sa, sa_orm, sa, sa_orm