Bug #7298
Removing relations in aggregate roots when deleting children
| Status: | Rejected | Start date: | 2010-04-16 | |
|---|---|---|---|---|
| Priority: | Should have | Due date: | ||
| Assignee: | Jochen Rau | % Done: | 0% |
|
| Category: | - | |||
| Target version: | Extbase 1.2.0beta3 | |||
| Has patch: | Tags: | |||
| Votes: | 0 |
Description
In my model I have an object "App" containing (mm) "Button" objects. Extbase seems to remove the relation to the Button in the App object when calling $this->buttonRepository->remove($button);
Here is my configuration, unnecessary parts stripped ([...]):
Objects:
class Tx_LalAppfactory_Domain_Model_App extends Tx_Extbase_DomainObject_AbstractEntity {
[...]
/**
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_LalAppfactory_Domain_Model_Button>
* @lazy
* @remove
*/
protected $buttons;
/**
* Constructor. Initializes all Tx_Extbase_Persistence_ObjectStorage instances.
*/
public function __construct() {
$this->buttons = new Tx_Extbase_Persistence_ObjectStorage();
}
[...]
/**
* Setter for buttons
*
* @param Tx_Extbase_Persistence_ObjectStorage $buttons One or more Tx_LalAppfactory_Domain_Model_Button objects
* @return void
*/
public function setButtons(Tx_Extbase_Persistence_ObjectStorage $buttons) {
$this->buttons = clone $buttons;
}
/**
* Adds a button to this branch
*
* @param Tx_LalAppfactory_Domain_Model_Button $button
* @return void
*/
public function addButton(Tx_LalAppfactory_Domain_Model_Button $button) {
$this->buttons->attach($button);
}
/**
* Removes a button from this branch
*
* @param Tx_LalAppfactory_Domain_Model_Button $button
* @return void
*/
public function removeButton(Tx_LalAppfactory_Domain_Model_Button $button) {
$this->buttons->detach($button);
}
/**
* Remove all buttons from this branch
*
* @return void
*/
public function removeAllButtons() {
$this->buttons = new Tx_Extbase_Persistence_ObjectStorage();
}
/**
* Getter for buttons
*
* @return Tx_Extbase_Persistence_ObjectStorage A storage holding Tx_LalAppfactory_Domain_Model_Button objects
*/
public function getButtons() {
return clone $this->buttons;
}
}
?>
class Tx_LalAppfactory_Domain_Model_Button extends Tx_Extbase_DomainObject_AbstractEntity {
[...]
}
?>
TCA:
$TCA['tx_lalappfactory_domain_model_app'] = array(
[...]
'buttons' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lal_appfactory/Resources/Private/Language/locallang_db.xml:tx_lalappfactory_domain_model_app.buttons',
'config' => array(
'type' => 'select',
'size' => 10,
'minitems' => 0,
'maxitems' => 9999,
'autoSizeMax' => 30,
'multiple' => 0,
'foreign_table' => 'tx_lalappfactory_domain_model_button',
'MM' => 'tx_lalappfactory_app_button_mm',
'wizards' => Array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'edit' => Array(
'type' => 'popup',
'title' => 'Edit',
'script' => 'wizard_edit.php',
'icon' => 'edit2.gif',
'popup_onlyOpenIfSelected' => 1,
'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
),
'add' => Array(
'type' => 'script',
'title' => 'Create new',
'icon' => 'add.gif',
'params' => Array(
'table'=>'tx_lalappfactory_domain_model_button',
'pid' => '###CURRENT_PID###',
'setValue' => 'prepend'
),
'script' => 'wizard_add.php',
),
)
)
),
),
);
History
Updated by Jochen Rau about 3 years ago
- Status changed from New to Accepted
Updated by Jochen Rau about 3 years ago
- Assignee set to Jochen Rau
Updated by Axel Böswetter about 3 years ago
In my opinion the relations shouldn't be removed. But the SQL query should respect the enableFields of the foreign table.
For example I have fe_users which can relate to other fe_users - contacts in short. So the query now looks like:
SELECT
fe_users.*
FROM
fe_users_user_mm
LEFT JOIN
fe_users ON fe_users_user_mm.uid_foreign = fe_users.uid
WHERE
fe_users_user_mm.uid_local = '8'
AND
(fe_users.tx_extbase_type='Tx_Example_Domain_Model_User')
ORDER BY
fe_users_user_mm.sorting ASC
Now I delete one of the fe_users, that fe_user (uid: 8) has as contacts via mm relation. So let's say fe_user (uid: 10) is deleted via backend, but the relation still exists, so fe_user (uid: 8) still sees the user in the frontend (via getContacts() in user model).
Imho, adding enable fields for the foreign table should do the trick. So it should look like this:
SELECT
fe_users.*
FROM
fe_users_user_mm
LEFT JOIN
fe_users ON fe_users_user_mm.uid_foreign = fe_users.uid
WHERE
fe_users_user_mm.uid_local = '8'
AND
(fe_users.tx_extbase_type='Tx_Example_Domain_Model_User')
AND
AND fe_users.deleted=0 AND fe_users.disable=0 AND fe_users.starttime<=1272411600 AND (fe_users.endtime=0 OR fe_users.endtime>1272411600)
ORDER BY
fe_users_user_mm.sorting ASC
I'm still not that familiar with the persistence/ query creating classes of extbase, so I can not provide a patch yet :-/
Updated by Jochen Rau about 3 years ago
- Target version changed from Extbase 1.1.0 to Extbase 1.2.0beta2
Updated by Jochen Rau almost 3 years ago
- Target version changed from Extbase 1.2.0beta2 to Extbase 1.2.0beta3
Updated by Jochen Rau almost 3 years ago
- Status changed from Accepted to Needs Feedback
Updated by Jochen Rau almost 3 years ago
In my opinion the relations shouldn't be removed. But the SQL query should respect the enableFields of the foreign table.
It depends.
If the object was removed and there is no "deleted" field it will be deleted from the database table. Thus, it makes no sense to store the relation anymore.
If the object was removed by setting deleted=1, the relation should also be set to deleted=1 (if there is a deleted field). This feature is currently not implemented in Extbase. I'd like to turn this bug into a feature ;-) and schedule it for v1.3.0.
The enableFields issue was resolved with r2315.
Updated by Robert Böttner almost 3 years ago
I can´t see why but I made a wrong problem description when reporting the bug. I explained all more clearly in the preceding mailinglist discussion: http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2010-April/003947.html
Anyway I tried to reproduce the behavior this morning on r2328 and everything is working as expected: deleting child objects also removes relation records. Which wasn´t the case when I reported the bug.
At the moment I can´t imagine any scenario where keeping relation records would be a feature. So the issue can be closed.
Thanks everyone.
Updated by Jochen Rau almost 3 years ago
- Status changed from Needs Feedback to Rejected