fix merging non relation list fields
This commit is contained in:
@ -60,20 +60,23 @@ class MergeModelMixin:
|
||||
:return: current Model instance with data merged from previous one.
|
||||
:rtype: Model
|
||||
"""
|
||||
for field in one.Meta.model_fields.keys():
|
||||
current_field = getattr(one, field)
|
||||
if isinstance(current_field, list) and not isinstance(
|
||||
current_field, ormar.Model
|
||||
):
|
||||
setattr(other, field, current_field + getattr(other, field))
|
||||
elif (
|
||||
isinstance(current_field, ormar.Model)
|
||||
and current_field.pk == getattr(other, field).pk
|
||||
):
|
||||
setattr(
|
||||
other,
|
||||
field,
|
||||
cls.merge_two_instances(current_field, getattr(other, field)),
|
||||
)
|
||||
for field_name, field in one.Meta.model_fields.items():
|
||||
current_field = getattr(one, field_name)
|
||||
if field.is_relation:
|
||||
if isinstance(current_field, list):
|
||||
setattr(
|
||||
other, field_name, current_field + getattr(other, field_name)
|
||||
)
|
||||
elif (
|
||||
isinstance(current_field, ormar.Model)
|
||||
and current_field.pk == getattr(other, field_name).pk
|
||||
):
|
||||
setattr(
|
||||
other,
|
||||
field_name,
|
||||
cls.merge_two_instances(
|
||||
current_field, getattr(other, field_name)
|
||||
),
|
||||
)
|
||||
other.set_save_status(True)
|
||||
return other
|
||||
|
||||
@ -150,15 +150,16 @@ class Model(ModelRow):
|
||||
for related in self.extract_related_names():
|
||||
if relation_map and related in relation_map:
|
||||
value = getattr(self, related)
|
||||
update_count = await self._update_and_follow(
|
||||
value=value,
|
||||
follow=follow,
|
||||
save_all=save_all,
|
||||
relation_map=self._skip_ellipsis( # type: ignore
|
||||
relation_map, related, default_return={}
|
||||
),
|
||||
update_count=update_count,
|
||||
)
|
||||
if value:
|
||||
update_count = await self._update_and_follow(
|
||||
value=value,
|
||||
follow=follow,
|
||||
save_all=save_all,
|
||||
relation_map=self._skip_ellipsis( # type: ignore
|
||||
relation_map, related, default_return={}
|
||||
),
|
||||
update_count=update_count,
|
||||
)
|
||||
return update_count
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user