4

I'm trying to use a m:n relation, the same way as FrontEndUser is related to FrontEndUserGroup, e.g. without intermediate mm table. In my controller, I build my object, then I call $barRepository->update($barObject); to update the values of my object. However, it fails on the update function with the error:

Fatal error: Call to undefined method Cbrunet\Up\Domain\Model\Foo::getPosition() in /home/cbrunet/websites/typo3_src-6.1.1/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php on line 486

where Foo is the type of the object contained in the ObjectStorage of Bar. My understanding is that getPosition should be called on the ObjectStorage, not on the object contained into that ObjectStorage. However, I cannot figure out why this is not working in my case.

This is in TYPO3 6.1.5. Any hint would be appreciated.


The model of Bar which has a m:n relation to Foo looks like:

namespace Cbrunet\Up\Domain\Model;

class Bar extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {

/**
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Cbrunet\Up\Domain\Model\Foo>
 */
protected $myprop;

public function __construct() {
    $this->myprop = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}

/**
 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $myprop
 * @return void
 */
public function setMyprop(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $myprop) {
    $this->myprop = $myprop;
}

/**
 * @param \Cbrunet\Up\Domain\Model\Foo $myprop
 * @return void
 */
public function addMyprop(\Cbrunet\Up\Domain\Model\Foo $myprop) {
    $this->myprop->attach($myprop);
}

/**
 * @param \Cbrunet\Up\Domain\Model\Foo $myprop
 * @return void
 */
public function removeMyprop(\Cbrunet\Up\Domain\Model\Foo $myprop) {
    $this->myprop->detach($myprop);
}

/**
 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
 */
public function getMyprop() {
    return $this->myprop;
}
}

The relevant code in my controller looks like:

/**
 * action update
 *
 * @return void
 */
public function updateAction() {
    $args = $this->request->getArgument('myargs');
    foreach ($args as $k=>$val) {
        $pp = $this->barRepository->findOneByAprop($k); // another prop of Bar, not illustrated in the code above.
        $listepour = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
        foreach ($val as $p) {
            $ap = $this->fooRepository->findOneByUid(intval($p));
            $listepour->attach($ap);
        }
        $pp->setMyprop($listepour);
        $this->barRepository->update($pp); // error occurs here
    }
    $this->redirect('list');
}
Charles Brunet
  • 21,797
  • 24
  • 83
  • 124

1 Answers1

3
  • Do you also have configured your TCA?
  • do you have an initStorageObjects-function in your domain model?

Also you can try to build these case with the extension-manager and compare the code.

freshp
  • 525
  • 5
  • 20
  • 1
    The missing part was the `initStorageObjects` function. Where is it documented? Why does FrontEndUser doesn't have this function? – Charles Brunet Oct 24 '13 at 13:49
  • 1
    because *frontenduser* has in his *construct*-method the same call like the *initstorageObjects* – freshp Oct 24 '13 at 15:38
  • but its a good question where it is documented!? thatswhy it is usefull to use the extension-manager to compare some settings – freshp Oct 24 '13 at 15:39
  • 6
    Indeed, I too wonder where such things are documented. I feel that after ExtBase and friends entered the arena it has become much harder to code for TYPO3. I love the framework and indeed the evolving codebase, but I find it hard to maintain steam when so much time goes into trying to work out how to do things. I would love reference grade documentation, but even a few links in the source saying "We discussed this here-and-here" would go a long way! – norwebian Mar 03 '14 at 19:56