You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The generator eliminates manual synchronization between TypeDB schemas and Python code. Instead of writing both `.tql` and Python classes, you write the schema once in TypeQL and generate type-safe Python models.
**Inheritance:** Child types inherit cardinality constraints from parent types. A child can override inherited constraints by redeclaring the attribute with a different `@card`.
- Filtering or deleting by a multi-player role uses the actual player’s key attributes and works across all allowed entity types.
246
250
- Role uniqueness rules still apply: keep role names distinct (TypeDB requirement).
247
251
@@ -277,6 +281,7 @@ class Employment(Relation):
277
281
```
278
282
279
283
**When explicit flags ARE needed:**
284
+
280
285
-`abstract=True` - Abstract relations
281
286
-`base=True` - Python-only base classes
282
287
- Custom `name` - Override type name
@@ -641,6 +646,43 @@ person plays authorship:author;
641
646
content plays authorship:content; # Abstract type in role player definition
642
647
```
643
648
649
+
### Polymorphic Role Player Type Resolution
650
+
651
+
When querying relations with polymorphic role players, TypeBridge resolves each role player to its **concrete type**, not the abstract declared type. This enables type-safe access to subtype-specific attributes:
652
+
653
+
```python
654
+
# Query authorships - role players are resolved to concrete types
655
+
authorships = Authorship.manager(db).all()
656
+
657
+
for authorship in authorships:
658
+
content = authorship.content
659
+
660
+
# content is Article, Video, or other concrete subtype - NOT abstract Content
661
+
ifisinstance(content, Article):
662
+
print(f"Article body: {content.body}")
663
+
elifisinstance(content, Video):
664
+
print(f"Video URL: {content.url}")
665
+
666
+
# Common attributes from abstract type are always accessible
667
+
print(f"Title: {content.title}")
668
+
```
669
+
670
+
**How it works**:
671
+
672
+
TypeBridge uses TypeDB's `label()` built-in function to fetch the actual type of each role player, then resolves it to the correct Python class. This happens automatically in:
0 commit comments