@@ -197,8 +197,12 @@ def __init__(self, db: AsyncEngine, model_or_table: Union[sa.Table, type[Declara
197197 mapper = sa .inspect (model_or_table )
198198 assert mapper is not None # noqa: S101
199199 for name , relationship in mapper .relationships .items ():
200+ # https://github.com/sqlalchemy/sqlalchemy/discussions/10161#discussioncomment-6583442
201+ assert relationship .local_remote_pairs # noqa: S101
200202 if len (relationship .local_remote_pairs ) > 1 :
201203 raise NotImplementedError ("Composite foreign keys not supported yet." )
204+ if not isinstance (relationship .entity .persist_selectable , sa .Table ):
205+ continue
202206 local , remote = relationship .local_remote_pairs [0 ]
203207
204208 props = {"reference" : relationship .entity .persist_selectable .name ,
@@ -214,11 +218,11 @@ def __init__(self, db: AsyncEngine, model_or_table: Union[sa.Table, type[Declara
214218 props ["link" ] = "show"
215219
216220 children = {}
217- for c in relationship .target .c .values ():
218- if c is remote : # Skip the foreign key
221+ for kc in relationship .target .c .values ():
222+ if kc is remote : # Skip the foreign key
219223 continue
220- field , inp , c_props = get_components (c .type )
221- children [c .name ] = {"type" : field , "props" : c_props }
224+ field , inp , c_props = get_components (kc .type )
225+ children [kc .name ] = {"type" : field , "props" : c_props }
222226 container = "Datagrid" if t == "ReferenceManyField" else "DatagridSingle"
223227 props ["children" ] = {"_" : {"type" : container , "props" : {
224228 "children" : children , "rowClick" : "show" }}}
0 commit comments