Refactor entity associations onto betty.attr#4265
Conversation
edefd78 to
6abf3fb
Compare
07d87cf to
201c028
Compare
5c00908 to
e438726
Compare
134c224 to
39e2efb
Compare
| """ | ||
|
|
||
| def __init__(self, wrapped: DataDefinition[DataClsT], /): | ||
| try: |
There was a problem hiding this comment.
We should revert this as the assumption in the data API is that everything is portable, hence the exception and no None return value. We should instead use temporary dummy porters for our associations.
There was a problem hiding this comment.
Is this where entity references come on stage again? Should we move them back into the entity API?
There was a problem hiding this comment.
I mean, ideally we add full serialization support now straight away. Probably nota bad idea because there are some issues we haven't thought out yet, e.g. how to resolve/hydrate loaded associations.
0ce4d34 to
14fe0cc
Compare
086024f to
1f8e423
Compare
|
|
||
|
|
||
| @final | ||
| class ToManyAssociates[OwnerT: Entity, AssociateT: Entity]( |
There was a problem hiding this comment.
Rename to ToManyCollection.
|
|
||
| @final | ||
| class ToManyAssociates[OwnerT: Entity, AssociateT: Entity]( | ||
| MutableCollection[AssociateT], |
There was a problem hiding this comment.
Make this a sequence too? Just a regular one, not mutable.
| is_entity = isinstance(associate, Entity) | ||
| if not is_entity: | ||
| self._resolved = False | ||
| elif associate in tuple( |
There was a problem hiding this comment.
Move this check outside the loop.
|
|
||
| def add(self, *associates: Associate[OwnerT, AssociateT]) -> None: | ||
| """ | ||
| Add the given associate. |
|
|
||
| def __init__( | ||
| self, | ||
| associate_type_name: str, |
There was a problem hiding this comment.
Allow types as well as names.
|
|
||
| def __init__( | ||
| self, | ||
| associate_type_name: str, |
There was a problem hiding this comment.
Allow types as well as names.
| location: ResolvableLocalizable | None = None, | ||
| date: AnyDate | None = None, | ||
| file_references: ToManyAssociates[FileReference] = (), | ||
| file_references: Iterable[Associate[Self, FileReference]] = (), |
There was a problem hiding this comment.
Add ToManyAssociates again
| id: str | None = None, # noqa: A002 | ||
| event_type: EventType | None = None, | ||
| date: AnyDate | None = None, | ||
| file_references: ToManyAssociates[FileReference] = (), |
There was a problem hiding this comment.
In a separate PR, rename HasFileReferences.file_references to .files.
This fixes #3581, and #3755, and #2778
To do
GrampsLoadersets inverse associates as well (it never had to). For those cases where a bidirectional association must be populated from unidirectional source data (common in Gramps), addBiResolverwhich wraps another resolver, and which uses the association to add the owner to the associate's inverse association.EntityReference.LinkedDataDumpableWithSchemaJsonLdObject.linked_data_schemawas updated to always make properties optional as an intermediate solution until this issue is fixed. Ensure properties are set to required depending on their aggregate element definitions.@todos