Bug #4650
Already existing records that are attached to a new parent are not persisted correctly.
| Status: | Resolved | Start date: | 2009-09-16 | |
|---|---|---|---|---|
| Priority: | Must have | Due date: | ||
| Assignee: | Jochen Rau | % Done: | 100% |
|
| Category: | - | |||
| Target version: | Extbase 1.2.0beta2 | |||
| Has patch: | Tags: | |||
| Votes: | 0 |
Description
I got a bunch of "homelesse" child records.
When i try to attache one of them to a new or existing parent record.
The parent gets save with its childs field set to 1 but the child records parent_uid and parent_tabel fields do not get updated.
It works for new created childs records.
If i tag the child record dirty (before or after adding - e.g. by changing one of its properties) it works.
Afaik we got a similar issue a while ago but i am not sure if its related to this one.
parent TCA:
'childs' => array(
'config' => array(
'type' => 'inline',
'foreign_class' => 'Tx_Dummy_Domain_Model_Child',
'foreign_table' => 'tx_dummy_domain_model_child',
'foreign_field' => 'parent_uid',
'foreign_table_field' => 'parent_table'
)
),
child TCA:
'parent_uid' => array(
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_dummy_domain_model_parent',
'foreign_table_where' => ' AND 1=1 ORDER BY ' .
'tx_dummy_domain_model_parent.surname,' .
'tx_dummy_domain_model_parent.forename,' .
'tx_dummy_domain_model_parent.username',
'items' => array(
array('unassigend', 0)
)
)
),
'parent_table' => array(
'config' => array(
'type' => 'passthrough'
)
)
Related issues
| duplicated by Extbase MVC Framework - Bug #6068: Adding existing frontendUserGroups to a frontendUser does... | Resolved | 2010-01-18 |
Associated revisions
History
Updated by Nikolas Hagelstein almost 4 years ago
the problem is cause by the fact that a relation isnt recognized as dirty if it's attached to a parent.
A dirty workaround is to add the following to line 341 of Backend.php
... || $parentObject !== NULL.
Unfortunatly this results in an update for all related records which could be a huge performance impact depending on the overall number of relational records.
Wouldnt it be better to flag the related record as dirty on "repository->add/attach" ?
Updated by Jochen Rau over 3 years ago
- Category set to 431
- Status changed from New to Accepted
- Assignee set to Jochen Rau
Updated by Nikolas Hagelstein over 3 years ago
Related to #5293
Updated by Jochen Rau over 3 years ago
- Status changed from Accepted to Needs Feedback
Could you please test with the latest revision, if the issue still occurs.
Updated by Kai Tallafus over 3 years ago
For me this issues still seems to exist. I tested with the newest revision (2001).
- I created a new domain model which extends the Tx_Extbase_Domain_Model_FrontendUser (just to add some new fields).
- created a simple registration form and a createAction to save the submitted data
- in the createAction i tried the following:
$userGroupRepository = t3lib_div::makeInstance('Tx_Extbase_Domain_Repository_FrontendUserGroupRepository');
$usergroup = $userGroupRepository->findByUid(1);
$newCustomer->addUsergroup($usergroup);
$this->userRepository->add($newCustomer);
The new customer is persisted, but the relation to the usergroup is not.
If I create a new usergroup:
$usergroup = new Tx_Extbase_Domain_Model_FrontendUserGroup();
$usergroup->setTitle('test');
$newCustomer->addUsergroup($usergroup);
$this->userRepository->add($newCustomer);
...the relation is saved correctly.
After some debugging the problem seems to exist in Tx_Extbase_Persistence_Backend::persistObjectStorage() where the $newUids only get´s some values if the related object is a new object ( if ($object->_isNew()) { .... ).
Since these are my first attempts on extbase I´m not sure if I got everything right, but I hope this helps somehow...
Updated by Jochen Rau about 3 years ago
- Target version set to Extbase 1.2.0beta2
Updated by Patrik Lang about 3 years ago
Hi,
I had a problem too saving relations for already existing records.
Now I have debugged a bit and found the following solution:
as Kai right mentioned the Problem seems to be in the method Tx_Extbase_Persistence_Backend::persistObjectStorage() near the foreach of $objectStorage
foreach ($objectStorage as $object) {
if ($object->_isNew()) {
...
$insertedObjectUids[] = $object->getUid();
}
...
}
Here only new Elements will be inserted into the array $insertedObjectUids[]. Is this needed in that if?
I changed it to:
foreach ($objectStorage as $object) {
if ($object->_isNew()) {
...
# $insertedObjectUids[] = $object->getUid();
}
$insertedObjectUids[] = $object->getUid();
...
}
And now it works for me. But I don't know if there could be some side effects? Because now every object is added to this array. But its just added to the right database column so it shouldn't make a problem.
Maybe this is the fix for next version?
Greets
Patrik
Updated by Jochen Rau about 3 years ago
- Status changed from Needs Feedback to Resolved
- % Done changed from 0 to 100
Applied in changeset r2291.