[TYPO3-mvc] Problem getting an instance of an object in controller

Henjo Hoeksma me at henjohoeksma.nl
Wed Apr 6 21:34:11 CEST 2011


On 2011-04-06 18:02:20 +0200, Franz Koch said:

> Hey,
> 
>> <code minified...>
>> case 'delete':
>> $rep =
>> $this->objectManager->get('Tx_Ext_Domain_Repository_ObjectRepository');
>> $object = $rep->findByProperty((int)$xml->value);
>> if(count($object) == '1'){
>> $rep->remove($object);
>> $response = '1';
>> } else {
>> $response = 'Delete action given, but the specified object was not found';
>> }
>> break;
>> </code>
>> 
>> Could it be because this object has a related object as well that should
>> be deleted? Should that object be instantiated as well (thought not so...)
> 
> no. As you noticed in your other posting the result is by default a 
> queryResult object. If you expect only one object to be returned, use 
> (like Sebastian said) the magic method "findOneByXXXX" which will 
> return either the Object or NULL.

Yeah... forgot I was adding fervently ending up with multiple instances 
of the same object in the db...

This makes sense now I got it ;-)

Thanks!

Henjo



More information about the TYPO3-project-typo3v4mvc mailing list