This commit is contained in:
@@ -4,6 +4,7 @@ from collections import defaultdict
|
||||
from typing import TypeVar, Generic, Dict, Optional, Iterable, List, Iterator, Tuple, Generator, Union, Any, Set
|
||||
from .parents import OuterProxy
|
||||
from ..utils import object_trace
|
||||
from ..utils import output, BColors
|
||||
|
||||
T = TypeVar('T', bound=OuterProxy)
|
||||
|
||||
@@ -80,11 +81,12 @@ class Collection(Generic[T]):
|
||||
for e in self:
|
||||
self._map_element(e)
|
||||
|
||||
def _find_object(self, __object: T) -> Optional[T]:
|
||||
for c in self.push_to:
|
||||
found, found_in = c._find_object(__object)
|
||||
if found is not None:
|
||||
return found, found_in
|
||||
def _find_object(self, __object: T, no_push_to: bool = False) -> Optional[T]:
|
||||
if not no_push_to:
|
||||
for c in self.push_to:
|
||||
found, found_in = c._find_object(__object, no_push_to=True)
|
||||
if found is not None:
|
||||
return found, found_in
|
||||
|
||||
self._remap()
|
||||
|
||||
@@ -104,10 +106,20 @@ class Collection(Generic[T]):
|
||||
:return:
|
||||
"""
|
||||
|
||||
|
||||
if __object is None:
|
||||
return
|
||||
|
||||
existing_object, map_to = self._find_object(__object)
|
||||
existing_object, map_to = self._find_object(__object, no_push_to=kwargs.get("no_push_to", False))
|
||||
|
||||
if map_to is self:
|
||||
for other, contained in (c._find_object(__object, no_push_to=True) for c in self.pull_from):
|
||||
output(other, __object, contained, color=BColors.RED)
|
||||
if other is None:
|
||||
continue
|
||||
|
||||
__object.__merge__(other, no_push_to=False, **kwargs)
|
||||
contained.remove(other)
|
||||
|
||||
if existing_object is None:
|
||||
# append
|
||||
@@ -135,22 +147,27 @@ class Collection(Generic[T]):
|
||||
b_data = b.data.copy()
|
||||
b_collection_for = b._collection_for.copy()
|
||||
no_sync_collection.add(id(b))
|
||||
kwargs["no_sync_collection"] = no_sync_collection
|
||||
# kwargs["no_sync_collection"] = no_sync_collection
|
||||
del b
|
||||
|
||||
a.extend(b_data, **kwargs)
|
||||
|
||||
for synced_with, key in b_collection_for.items():
|
||||
synced_with.__setattr__(key, a)
|
||||
a._collection_for[synced_with] = key
|
||||
|
||||
a.extend(b_data, **kwargs)
|
||||
|
||||
else:
|
||||
# merge only if the two objects are not the same
|
||||
if existing_object.id == __object.id:
|
||||
return
|
||||
|
||||
existing_object.merge(__object, **kwargs)
|
||||
map_to._map_element(existing_object)
|
||||
map_to._map_element(existing_object)
|
||||
|
||||
def remove(self, __object: T) -> T:
|
||||
self._data.remove(__object)
|
||||
self._unmap_element(__object)
|
||||
return __object
|
||||
|
||||
def contains(self, __object: T) -> bool:
|
||||
return self._find_object(__object) is not None
|
||||
|
@@ -144,6 +144,7 @@ class Song(Base):
|
||||
}
|
||||
|
||||
self.feature_artist_collection.push_to = [self.main_artist_collection]
|
||||
self.main_artist_collection.pull_from = [self.feature_artist_collection]
|
||||
|
||||
def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]):
|
||||
if object_type is Song:
|
||||
|
Reference in New Issue
Block a user