fix: merging and replacing instances
This commit is contained in:
@@ -2,13 +2,13 @@ from typing import List, Iterable, Iterator, Optional, TypeVar, Generic, Dict, T
|
||||
from collections import defaultdict
|
||||
|
||||
from .parents import DatabaseObject
|
||||
from ..utils.functions import replace_all_refs
|
||||
from ..utils.support_classes.hacking import MetaClass
|
||||
|
||||
|
||||
T = TypeVar('T', bound=DatabaseObject)
|
||||
|
||||
|
||||
class Collection(Generic[T]):
|
||||
class Collection(Generic[T], metaclass=MetaClass):
|
||||
_data: List[T]
|
||||
|
||||
_indexed_values: Dict[str, set]
|
||||
@@ -109,7 +109,7 @@ class Collection(Generic[T]):
|
||||
|
||||
# now the ugly part
|
||||
# replace all refs of the other element with this one
|
||||
replace_all_refs(self, equal_collection)
|
||||
self.merge(equal_collection)
|
||||
|
||||
|
||||
def contain_collection_inside(self, sub_collection: "Collection"):
|
||||
|
||||
@@ -7,7 +7,7 @@ from .metadata import Metadata
|
||||
from .option import Options
|
||||
from ..utils.shared import HIGHEST_ID
|
||||
from ..utils.config import main_settings, logging_settings
|
||||
from ..utils.functions import replace_all_refs
|
||||
from ..utils.support_classes.hacking import MetaClass
|
||||
|
||||
|
||||
LOGGER = logging_settings["object_logger"]
|
||||
@@ -43,7 +43,7 @@ class Attribute(Generic[P]):
|
||||
|
||||
|
||||
|
||||
class DatabaseObject:
|
||||
class DatabaseObject(metaclass=MetaClass):
|
||||
COLLECTION_STRING_ATTRIBUTES: tuple = tuple()
|
||||
SIMPLE_STRING_ATTRIBUTES: dict = dict()
|
||||
|
||||
@@ -170,7 +170,7 @@ class DatabaseObject:
|
||||
setattr(self, simple_attribute, getattr(other, simple_attribute))
|
||||
|
||||
if replace_all_refs:
|
||||
replace_all_refs(self, other)
|
||||
self.merge(other)
|
||||
|
||||
def strip_details(self):
|
||||
for collection in type(self).DOWNWARDS_COLLECTION_STRING_ATTRIBUTES:
|
||||
|
||||
Reference in New Issue
Block a user