From 2feaba7bf4ffae2e37a85cac5c9d2b85bf95306a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 18 Dec 2022 21:03:12 +0100 Subject: [PATCH] Add children_ids attribute to entities when converted to JSON --- platypush/entities/_base.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/platypush/entities/_base.py b/platypush/entities/_base.py index 71e231a6..988ea4b3 100644 --- a/platypush/entities/_base.py +++ b/platypush/entities/_base.py @@ -73,6 +73,7 @@ if 'entity' not in Base.metadata: remote_side=[parent_id], uselist=True, cascade='all, delete-orphan', + lazy='immediate', ), ) @@ -110,16 +111,10 @@ if 'entity' not in Base.metadata: return val - def copy(self) -> 'Entity': - args = {c.key: getattr(self, c.key) for c in self.columns} - # if self.parent: - # args['parent'] = self.parent.copy() - - # args['children'] = [c.copy() for c in self.children] - return self.__class__(**args) - def to_json(self) -> dict: - return {col.key: self._serialize_value(col) for col in self.columns} + obj = {col.key: self._serialize_value(col) for col in self.columns} + obj['children_ids'] = [e.id for e in self.children] + return obj def __repr__(self): return str(self)