title: TYPO3 extbase: how to use ObjectStorage?
body: <p>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 <code>$barRepository-&gt;update($barObject);</code> to update the values of my object. However, it fails on the update function with the error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>where <code>Foo</code> is the type of the object contained in the ObjectStorage of Bar. My understanding is that <code>getPosition</code> should be called on the <code>ObjectStorage</code>, not on the object contained into that <code>ObjectStorage</code>. However, I cannot figure out why this is not working in my case.</p>
  
  <p>This is in TYPO3 6.1.5. Any hint would be appreciated.</p>
  
  <hr>
  
  <p>The model of <code>Bar</code> which has a m:n relation to <code>Foo</code> looks like:</p>
  
  <pre><code>namespace Cbrunet\Up\Domain\Model;
  
  class Bar extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
  
  /**
   * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage&lt;\Cbrunet\Up\Domain\Model\Foo&gt;
   */
  protected $myprop;
  
  public function __construct() {
      $this-&gt;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-&gt;myprop = $myprop;
  }
  
  /**
   * @param \Cbrunet\Up\Domain\Model\Foo $myprop
   * @return void
   */
  public function addMyprop(\Cbrunet\Up\Domain\Model\Foo $myprop) {
      $this-&gt;myprop-&gt;attach($myprop);
  }
  
  /**
   * @param \Cbrunet\Up\Domain\Model\Foo $myprop
   * @return void
   */
  public function removeMyprop(\Cbrunet\Up\Domain\Model\Foo $myprop) {
      $this-&gt;myprop-&gt;detach($myprop);
  }
  
  /**
   * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
   */
  public function getMyprop() {
      return $this-&gt;myprop;
  }
  }
  </code></pre>
  
  <p>The relevant code in my controller looks like:</p>
  
  <pre><code>/**
   * action update
   *
   * @return void
   */
  public function updateAction() {
      $args = $this-&gt;request-&gt;getArgument('myargs');
      foreach ($args as $k=&gt;$val) {
          $pp = $this-&gt;barRepository-&gt;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-&gt;fooRepository-&gt;findOneByUid(intval($p));
              $listepour-&gt;attach($ap);
          }
          $pp-&gt;setMyprop($listepour);
          $this-&gt;barRepository-&gt;update($pp); // error occurs here
      }
      $this-&gt;redirect('list');
  }
  </code></pre>