add support for sqlalchemy AssociationProxys (#2809)
* add support for sqlalchemy AssociationProxys * python 3.8 compatibility
This commit is contained in:
parent
19a5cdd408
commit
f5b7eca9c7
@ -23,6 +23,7 @@ from typing import (
|
|||||||
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
from pydantic.fields import ModelField
|
from pydantic.fields import ModelField
|
||||||
|
from sqlalchemy.ext.associationproxy import AssociationProxyInstance
|
||||||
from sqlalchemy.ext.hybrid import hybrid_property
|
from sqlalchemy.ext.hybrid import hybrid_property
|
||||||
from sqlalchemy.orm import DeclarativeBase, Mapped, QueryableAttribute, Relationship
|
from sqlalchemy.orm import DeclarativeBase, Mapped, QueryableAttribute, Relationship
|
||||||
|
|
||||||
@ -194,6 +195,13 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
|
|||||||
return List[class_]
|
return List[class_]
|
||||||
else:
|
else:
|
||||||
return class_
|
return class_
|
||||||
|
if isinstance(attr, AssociationProxyInstance):
|
||||||
|
return List[
|
||||||
|
get_attribute_access_type(
|
||||||
|
attr.target_class,
|
||||||
|
attr.remote_attr.key, # type: ignore[attr-defined]
|
||||||
|
)
|
||||||
|
]
|
||||||
elif isinstance(cls, type) and issubclass(cls, Model):
|
elif isinstance(cls, type) and issubclass(cls, Model):
|
||||||
# Check in the annotations directly (for sqlmodel.Relationship)
|
# Check in the annotations directly (for sqlmodel.Relationship)
|
||||||
hints = get_type_hints(cls)
|
hints = get_type_hints(cls)
|
||||||
|
Loading…
Reference in New Issue
Block a user