public function sync($ids)
	{
		if (is_array($ids))
		{
			// Get a query instance
			$query = $this->model->getQuery();

			// Get the parent primary key value
			$localKeyValue = $this->model->getPkValue();

			// Get any existing entries
			$existing = $query->select($this->associativeRelated)
			                  ->from($this->associativeTable)
			                  ->whereEquals($this->associativeLocal, $localKeyValue)
			                  ->fetch('column');

			// See if there's anything to delete
			$deletes = array_diff($existing, $ids);
			if (!empty($deletes))
			{
				$query->delete($this->associativeTable)
				      ->whereEquals($this->associativeLocal, $localKeyValue)
				      ->whereIn($this->associativeRelated, $deletes)
				      ->execute();
			}

			// Now see if there's anything to add
			$inserts = array_diff($ids, $existing);
			$this->connect($inserts);
		}

		return $this;
	}
public function sync($ids)
	{
		if (is_array($ids))
		{
			// Get a query instance
			$query = $this->model->getQuery();

			// Get the parent primary key value
			$localKeyValue = $this->model->getPkValue();

			// Get any existing entries
			$existing = $query->select($this->associativeRelated)
			                  ->from($this->associativeTable)
			                  ->whereEquals($this->associativeLocal, $localKeyValue)
			                  ->fetch('column');

			// See if there's anything to delete
			$deletes = array_diff($existing, $ids);
			if (!empty($deletes))
			{
				$query->delete($this->associativeTable)
				      ->whereEquals($this->associativeLocal, $localKeyValue)
				      ->whereIn($this->associativeRelated, $deletes)
				      ->execute();
			}

			// Now see if there's anything to add
			$inserts = array_diff($ids, $existing);
			$this->connect($inserts);
		}

		return $this;
	}
public function sync ( $ ids ) { if ( is_array ( $ ids ) ) { // Get a query instance $ query = $ this -> model -> getQuery ( ) ; // Get the parent primary key value $ localKeyValue = $ this -> model -> getPkValue ( ) ; // Get any existing entries $ existing = $ query -> select ( $ this -> associativeRelated ) -> from ( $ this -> associativeTable ) -> whereEquals ( $ this -> associativeLocal , $ localKeyValue ) -> fetch ( 'column' ) ; // See if there's anything to delete $ deletes = array_diff ( $ existing , $ ids ) ; if ( ! empty ( $ deletes ) ) { $ query -> delete ( $ this -> associativeTable ) -> whereEquals ( $ this -> associativeLocal , $ localKeyValue ) -> whereIn ( $ this -> associativeRelated , $ deletes ) -> execute ( ) ; } // Now see if there's anything to add $ inserts = array_diff ( $ ids , $ existing ) ; $ this -> connect ( $ inserts ) ; } return $ this ; }
Syncs the provided identifiers back to the parent model by way of associative entities,
deleting ones that should no longer be there, and adding ones that are missing.

@param   array  $ids  The identifiers to place in the associative table
@return  $this
@since   2.0.0
Syncs the provided identifiers back to the parent model by way of associative entities deleting ones that should no longer be there and adding ones that are missing .