@@ -197,8 +197,12 @@ def __init__(self, db: AsyncEngine, model_or_table: Union[sa.Table, type[Declara
197
197
mapper = sa .inspect (model_or_table )
198
198
assert mapper is not None # noqa: S101
199
199
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
200
202
if len (relationship .local_remote_pairs ) > 1 :
201
203
raise NotImplementedError ("Composite foreign keys not supported yet." )
204
+ if not isinstance (relationship .entity .persist_selectable , sa .Table ):
205
+ continue
202
206
local , remote = relationship .local_remote_pairs [0 ]
203
207
204
208
props = {"reference" : relationship .entity .persist_selectable .name ,
@@ -214,11 +218,11 @@ def __init__(self, db: AsyncEngine, model_or_table: Union[sa.Table, type[Declara
214
218
props ["link" ] = "show"
215
219
216
220
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
219
223
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 }
222
226
container = "Datagrid" if t == "ReferenceManyField" else "DatagridSingle"
223
227
props ["children" ] = {"_" : {"type" : container , "props" : {
224
228
"children" : children , "rowClick" : "show" }}}
0 commit comments