Welcome! Please see the About page for a little more info on how this works.

0 votes
in Cloud by

In my database model, I have several entities referencing the user entity.
When I retract the user entity using :db/retractEntity, the user is correctly retracted, as well as its refs in the other entities, for example :message/user.
For some entities, when the user is retracted the entity itself should also be retracted, but since the entity is not a component of the user, as the relation is the other way around, I did not find a way to retract the entire entity.
Is there a way to make this happen for some entities?

1 Answer

0 votes
by

I can see some different ways to solve this problem:

The first one is to make a special custom retraction function that, given a user entity eid, also looks up the other entities that should be retracted according to some rule. This requires quite a lot of discipline in the programming of the update logic.

The second solution is to add a special component attribute, only used for removing related data, preferably multiarity. When a message that refers a used is created or somehow delivered to that user, you also add a link from the user back to the message. Now, when the user entity is removed, the special component attribute linked form the user to message also removes the users messages.

The third solution is to introduce a certain reference attribute (a very generic name could be :entity/owns) that is not a component attribute, but can be introspected with a special retract-entity function (on the peer side), that looks up all the links of this special attribute and see whether related entities should be removed as well, given a root eid.

A fourth solution is to introduce a special attribute that can mark attributes like :message/user and give a retract-strategy. When your custom retract-entity function creates retraction data for a certain entity, it also looks for attributes in this entity tagged with some certain retract strategy. Like a more advanced :db/isComponent attribute.

...