Isn't DeletePolicy.Unlink supposed to ... unlink things rather than DELETE THEM!?

So I have a need to add a list of users (sec$Users) to an entity, representing the list of users that can see/access things that are associated to it (which I will deal with via custom constraints in code; see my other epic thread; but not important to this issue).

Easy, yeah? Added the many:many association to the entity, set delete policy to unlink and went to test. Added a user. Then removed the user. THE USER WAS DELETED FROM THE DATABASE.

Obviously, undesirable behavior. I thought that’s what cascade did. Leaving delete policy blank also produces a delete of the user.

What the heck have I done wrong here?

1 Like

Hi @jon.craig,
There is not enough info, but are you using composition or association? Given your description, you should use association.

https://doc.cuba-platform.com/manual-7.2/entity_attr_annotations.html#composition_annotation

Regards,
Peterson.

Yeah, it’s an association, marked many:many, with the CUBA-created join table. I can’t make this work; it deletes the user every single time.

I ultimately just made the join table an entity and handled it that way and it’s working fine.

Hi,
You probably had to use “exclude” action instead of “remove” in your first implementation.

See: ExcludeAction - CUBA Platform. Developer’s Manual

ExcludeAction is a list action designed to remove entity instances from a data container in UI. Unlike RemoveAction, ExcludeAction does not remove the selected instance from the database. It is required, for example, when working with a many-to-many collection.

Indeed; that’s it exactly. Another area where I feel documentation could be improved.