Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
self._check_model_exists()
data = payload[self.Meta.name]
data_to_update = self._to_update(data)
ids = get_ids_from_payload(self.Meta.model, data_to_update)
session.bulk_update_mappings(self.Meta.model, data_to_update)
self._save_m2m(session, data, update=True)
result = self.read_handler(
session=session,
user_id=user_id,
filters=[FilterItem.create("id", OP_IN, ids)],
)
return result
data_to_insert = [self._to_create(i) for i in data]
# insert to DB
resource_ids = bulky.insert(
session,
self.Meta.model,
data_to_insert,
returning=[self.Meta.model.id],
)
ids = [r.id for r in resource_ids]
result = self.read_handler(
session=session,
user_id=user_id,
filters=[FilterItem.create("id", OP_IN, ids)],
)
return result