/** * {@inheritDoc} */ public function add($lhs, $rhs, $additionalFields = array()) { $result = parent::add($lhs, $rhs, $additionalFields); if ($result) { $this->registerUserAclRoles($rhs); } return $result; }
/** * @param $lhs SugarBean left side bean to add to the relationship. * @param $rhs SugarBean right side bean to add to the relationship. * @param $additionalFields key=>value pairs of fields to save on the relationship * @return boolean true if successful */ public function add($lhs, $rhs, $additionalFields = array()) { $dataToInsert = $this->getRowToInsert($lhs, $rhs, $additionalFields); //If the current data matches the existing data, don't do anything if (!$this->checkExisting($dataToInsert)) { $lhsLinkName = $this->lhsLink; $rhsLinkName = $this->rhsLink; //In a one to one, any existing links from boths sides must be removed first. //one2Many will take care of the right side, so we'll do the left. $lhs->load_relationship($lhsLinkName); $this->removeAll($lhs->{$lhsLinkName}); $rhs->load_relationship($rhsLinkName); $this->removeAll($rhs->{$rhsLinkName}); parent::add($lhs, $rhs, $additionalFields); } }
/** * @param $lhs SugarBean left side bean to add to the relationship. * @param $rhs SugarBean right side bean to add to the relationship. * @param $additionalFields key=>value pairs of fields to save on the relationship * @return boolean true if successful */ public function add($lhs, $rhs, $additionalFields = array()) { $dataToInsert = $this->getRowToInsert($lhs, $rhs, $additionalFields); //If the current data matches the existing data, don't do anything if (!$this->checkExisting($dataToInsert)) { $rhsLinkName = $this->rhsLink; //In a one to many, any existing links from the many (right) side must be removed first $rhs->load_relationship($rhsLinkName); $this->removeAll($rhs->{$rhsLinkName}); parent::add($lhs, $rhs, $additionalFields); } }
/** * @param $lhs SugarBean left side bean to add to the relationship. * @param $rhs SugarBean right side bean to add to the relationship. * @param $additionalFields key=>value pairs of fields to save on the relationship * @return boolean true if successful */ public function add($lhs, $rhs, $additionalFields = array()) { $dataToInsert = $this->getRowToInsert($lhs, $rhs, $additionalFields); //If the current data matches the existing data, don't do anything if (!$this->checkExisting($dataToInsert)) { // If it's a One2Many self-referencing relationship // the positions of the default One (LHS) and Many (RHS) are swaped // so we should clear the links from the many (left) side if ($this->selfReferencing) { // Load right hand side relationship name $linkName = $this->rhsLink; // Load the relationship into the left hand side bean $lhs->load_relationship($linkName); // Pick the loaded link $link = $lhs->{$linkName}; // Get many (LHS) side bean $focus = $link->getFocus(); // Get relations $related = $link->getBeans(); // Clear the relations from many side bean foreach ($related as $relBean) { $this->remove($focus, $relBean); } } else { // For non self-referencing, just load the many (RHS) side, and remove all the relationships from it $rhsLinkName = $this->rhsLink; //In a one to many, any existing links from the many (right) side must be removed first $rhs->load_relationship($rhsLinkName); $this->removeAll($rhs->{$rhsLinkName}); } // Add relationship parent::add($lhs, $rhs, $additionalFields); } }
/** * @param $lhs SugarBean left side bean to add to the relationship. * @param $rhs SugarBean right side bean to add to the relationship. * @param $additionalFields key=>value pairs of fields to save on the relationship * @return boolean true if successful */ public function add($lhs, $rhs, $additionalFields = array()) { $dataToInsert = $this->getRowToInsert($lhs, $rhs, $additionalFields); //If the current data matches the existing data, don't do anything if (!$this->checkExisting($dataToInsert)) { // Pre-load the RHS relationship, which is used later in the add() function and expects a Bean // and we also use it for clearing relationships in case of non self-referencing O2M relations // (should be preloaded because when using the relate_to field for updating/saving relationships, // only the bean id is loaded into $rhs->$rhsLinkName) $rhsLinkName = $this->rhsLink; $rhs->load_relationship($rhsLinkName); // If it's a One2Many self-referencing relationship // the positions of the default One (LHS) and Many (RHS) are swaped // so we should clear the links from the many (left) side if ($this->selfReferencing) { // Load right hand side relationship name $linkName = $this->rhsLink; // Load the relationship into the left hand side bean $lhs->load_relationship($linkName); // Pick the loaded link $link = $lhs->{$linkName}; // Get many (LHS) side bean $focus = $link->getFocus(); // Get relations $related = $link->getBeans(); // Clear the relations from many side bean foreach ($related as $relBean) { $this->remove($focus, $relBean); } } else { // For non self-referencing, remove all the relationships from the many (RHS) side $this->removeAll($rhs->{$rhsLinkName}); } // Add relationship parent::add($lhs, $rhs, $additionalFields); } }
/** * @param $lhs SugarBean left side bean to add to the relationship. * @param $rhs SugarBean right side bean to add to the relationship. * @param $additionalFields key=>value pairs of fields to save on the relationship * @return boolean true if successful */ public function add($lhs, $rhs, $additionalFields = array()) { $dataToInsert = $this->getRowToInsert($lhs, $rhs, $additionalFields); //If the current data matches the existing data, don't do anything if (!$this->checkExisting($dataToInsert)) { // Pre-load the RHS relationship, which is used later in the add() function and expects a Bean // and we also use it for clearing relationships in case of non self-referencing O2M relations // (should be preloaded because when using the relate_to field for updating/saving relationships, // only the bean id is loaded into $rhs->$rhsLinkName) $rhsLinkName = $this->rhsLink; $rhs->load_relationship($rhsLinkName); // For self-referencing from 6.5.x // The left side is one, and right side is many if ($this->isRHSMany()) { $lhsLinkName = $this->lhsLink; $lhs->load_relationship($lhsLinkName); $this->removeAll($lhs->{$lhsLinkName}); } else { // For non self-referencing, remove all the relationships from the many (RHS) side $this->removeAll($rhs->{$rhsLinkName}); } // Add relationship parent::add($lhs, $rhs, $additionalFields); } }