Feature #44458

Allow deletion of sub objects

Added by Bastian Waidelich over 2 years ago. Updated over 1 year ago.

Status:Closed Start date:2013-01-11
Priority:Could have Due date:
Assigned To:Bastian Waidelich % Done:

0%

Category:Property
Target version:-
PHP Version: Complexity:
Has patch:No

Description

Currently it's not possible to remove a subobject from an entity in it's updateAction without manual interaction.

Example:

Imagine you have a domain object Invoice with 1:n relation to Client and a n:n relation to InvoiceItem
I want to display the invoice with its items and the related client.
The user should be able to remove items and the client from the invoice and submit the form.

Note: A solution would be to remove relations via AJAX but that's a different topic

RFC:

I could imagine following solution:

Submit the form with

1<input type="hidden" name="client[__remove]" value="1" />
2<input type="hidden" name="items[__remove]" value="UUID1, UUID2" />

an alternative syntax for the collection removal could be:

1<input type="hidden" name="items[__remove][UUID1]" value="1" />
2<input type="hidden" name="items[__remove][UUID2]" value="1" />

The PersistentObjectConverter would have to take care of the removals probably.

Security:

We probably need a new constant PersistentObjectConverter::CONFIGURATION_DELETION_ALLOWED (in addition to CREATION and MODIFICATION) which need to be set in the propertyMappingConfiguration for the corresponding object.

History

#1 Updated by Bastian Waidelich over 2 years ago

  • Priority changed from Should have to Could have

The above statement is not entirely true actually:
If you submit at least one item of a collection, the whole collection is replaced.
Thus it should be possible to remove single items from a collection by removing the respective form fields (e.g. via JavaScript).

This feature would still make sense for the client example and if you want to remove an item from the database

#2 Updated by Karsten Dambekalns over 2 years ago

Bastian Waidelich wrote:

If you submit at least one item of a collection, the whole collection is replaced.

True.

Thus it should be possible to remove single items from a collection by removing the respective form fields (e.g. via JavaScript).

No - because "no fields transferred" means "no change" with the current implementation.

#3 Updated by Marco Falkenberg over 2 years ago

Currently the property PersistentObjectConverter distinguishes not between collection or "normal" properties. I.e. collections gets replaced by their "incoming" collection. Thus partial updates are not possible.

My suggestion would be to offer the configuration of a MappingMode for collections in the PersistentObjectConverter. That could be "Replace" & "Merge".

  • Replace
    is the default setting and replaces the collection as like in the current situation.
  • Merge
    adds new subitems, updates existing and deletes the ones that are marked as deleted (e.g. by some internal '__remove'-flags as Bastian mentioned above).
    IMHO only adding & deleting has to be considered in the implementation, because updates are done by converting the child-properties of the CollectionConverter.

#4 Updated by Bastian Waidelich over 1 year ago

  • Status changed from New to Closed
  • Assigned To set to Bastian Waidelich

..after a long time: It is actually possible to delete single items like so:

Before:

Item01 (UUID1):
 name: "Some name" 
Item02 (UUID2):
 name: "Some other name" 

1<input type="hidden" name="items" value="" />
2
3<input type="hidden" name="items[0][__identity]" value="<UUID1>" />
4<input type="hidden" name="items[0][name]" value="New name" />

Afterwards:

Item01 (UUID1):
 name: "New name" 

Note: The first hidden field makes sure that all items are removed if no further items[n] entry is sent.

Fluid already adds these hidden fields automatically, so this works out-of-the-box:

1<f:form.select property="items" multiple="true" options="{items}" />

Also available in: Atom PDF