Domain object doesn't get persisted correct
After I create new domain object, set all properties values, then persist, field where i assigned child domain object doesn't get updated.
$userAnswer = $this->objectManager->get(UserAnswer::class); $question = $this->objectManager->get(QuestionRepository::class)->findByUid(1); $userAnswer->setQuestion($question); $userAnswer->setPid($question->getPid()); $this->objectManager->get(PersistenceManager::class)->persistAll();
And my "question" object is not attached to "user answer", field in DB remains to be zero.
In my TCA configuration file "tx_pxasurvey_domain_model_useranswer.php" i have field configuration:
'question' => [ 'exclude' => true, 'label' => $ll . 'tx_pxasurvey_domain_model_useranswer.question', 'config' => [ 'type' => 'select', 'renderType' => 'selectSingle', 'foreign_table' => 'tx_pxasurvey_domain_model_question', 'foreign_table_where' => 'AND tx_pxasurvey_domain_model_question.deleted=0', 'size' => 1, 'maxitems' => 1 ], ],
In "ext_tables.sql" "question int(11) unsigned DEFAULT '0'"
In model "UserAnswer.php"
/** * question * * @var \Pixelant\PxaSurvey\Domain\Model\Question */ protected $question = null;
After investigation, I find out that this might be caused by "_isDirty()" check in "\TYPO3\CMS\Extbase\Persistence\Generic\Backend" on line "397", where it returns "false".
Does it missing check with property name "$object->_isDirty($propertyName)"?
Updated by Daniel Lorenz about 2 years ago
I think this error is caused by this change: https://review.typo3.org/#/c/58123/2/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php
Adding the $propertyName to _isDirty() saves the question property to the new $userAnswer object.