[TYPO3-mvc] Strange behaviour when update($object) - not all attributes was written to the database.

Daniel Lorenz mailinglists at capsicumnet.de
Thu Jan 13 21:20:26 CET 2011


Hello guys,

my extension shows a strange behaviour, when updating an object in
action. I have a model $foo and a model $bar and every $foo has a $bar.

--- begin ---
$foo = $this->fooRepository->findOneBySomething($something);
var_dump($foo->getBar()->getUid());

if ($foo != NULL) {
	$foo->setBar($bar);
	$foo->setAnattribute(true);
	$this->fooRepository->update($foo);
} else {
	$newFoo = new Tx_Capaudit_Domain_Model_Foo();
	$newFoo->setBar($bar);
	$newFoo->setAnattribute(true);
	$this->fooRepository->add($newFoo);
}
		
$persistenceManager =
t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();

$foo = $this->fooRepository->findOneBySomething($something);
var_dump($foo->getBar()->getUid());

exit;
--- end ---

I get the object $foo from the repository, if there is one.
When no $foo is found, then a new Foo was created with the correct $bar
and an given attribute.
Everything works correct.

When a $foo was found, I set the $bar and the attibute. The last
var_dump after persisting shows me that the uid of bar has changed. But
in the database only the one attribute was written. $bar has the same id
as before.

I think I checked everything, TCA, the setter in model, ...

Why only one of two changes was written to the database.

Daniel



More information about the TYPO3-project-typo3v4mvc mailing list