Cake\ORM\Association\BelongsToMany::saveStrategy PHP Method

saveStrategy() public method

Sets the strategy that should be used for saving. If called with no arguments, it will return the currently configured strategy
public saveStrategy ( string | null $strategy = null ) : string
$strategy string | null the strategy name to be used
return string the strategy to be used for saving
    public function saveStrategy($strategy = null)
    {
        if ($strategy === null) {
            return $this->_saveStrategy;
        }
        if (!in_array($strategy, [self::SAVE_APPEND, self::SAVE_REPLACE])) {
            $msg = sprintf('Invalid save strategy "%s"', $strategy);
            throw new InvalidArgumentException($msg);
        }
        return $this->_saveStrategy = $strategy;
    }

Usage Example

コード例 #1
0
ファイル: BelongsToManyTest.php プロジェクト: rashmi/newrepo
 /**
  * Tests that it is possible to pass the saveAssociated strategy in the constructor
  *
  * @return void
  */
 public function testSaveStrategyInOptions()
 {
     $assoc = new BelongsToMany('Test', ['saveStrategy' => BelongsToMany::SAVE_APPEND]);
     $this->assertEquals(BelongsToMany::SAVE_APPEND, $assoc->saveStrategy());
 }