Hi Faizel,

If you don't have many entities where deleting is important, you could put
"delete" type methods in your subclasses.  For example, if you have
LineItem and a to-many to Order, in LineItem.java add a
deleteFromOrders(Order order) { ... } method which will remove and delete
the Order object.  If you have many entities, it might be easier to create
your own Velicity template (using the current Velocity template as a guide)
and add new code for a deleteFromX(X x) { ... } type method for each
to-many relationship.  If you go that route and need help, please ask.

The reason Cayenne doesn't automatically delete objects is you might be
moving them.  For example, if your LineItem has both fulfilledOrders and
unfulfilledOrders to-many relationships, you can remove an Order from the
unfulfilled relationship and add it to the fulfilled relationship.  When
you commit, Cayenne updates the FKs for you and no delete/insert is done.

mrg


On Sun, Jul 12, 2020 at 5:35 PM Faizel Dakri <list...@dakri.com> wrote:

> Is there a facility in Cayenne to automatically delete an object when it
> is removed from an “owning” object’s to-many relationship (and not added to
> another owning object)?
>
> I’m migrating a project from EOF to Cayenne. In the EOF world, there was
> the concept of a relationship owning its destination, meaning that removing
> a destination object from that relationship in the source object would also
> cause that destination object to be deleted from the database on commit
> without having to explicitly call deleteObject() on it (provided it wasn’t
> subsequently added to another source object). This automatic deletion would
> happen during saveChanges() on the editing context.
>
> Maybe it’s just too obvious and I haven’t been able to recognize it, but I
> have not been able to find anything similar in Cayenne. Is there such a
> feature?
>
> Thanks,
>
> F
>
> --
> Faizel Dakri
>
>
>

Reply via email to