We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38371
    • 42 Posts
    Hello to everyone,

    In an modObjectUpdateProcessor I try to save an object A and its one-to-one related object B. The data coming from the request shows if A is already related to one B or not.

    So, if there is no relationship I want to create a new B and add to A. That is why I use:

    public function beforeSave() {
        if (A not related to any B) {
            $newB = $this->modx->newObject('B', array with B's properties);
            $this->object->addOne($newB);
        }
    
        return parent::beforeSave();
    }
    


    However, the above code results in two new entries in the relationship table, instead of the one I expect.

    Can anyone explain why this is happening?


    Thanks a lot.
      • 38371
      • 42 Posts
      I've noticed that xPDOObject::save() calls xPDOObject::_saveRelatedObjects() twice.

      Could that be related to the problem above?