Sync the intermediate tables with a list of IDs or collection of models.

@param  array  $ids
@param  bool   $detaching
@return array
769413
public function sync($ids, $detaching = true)
	{
		$changes = array(
			'attached' => array(), 'detached' => array(), 'updated' => array(),
		);

		if ($ids instanceof Collection) $ids = $ids->modelKeys();

		// First we need to attach any of the associated models that are not currently
		// in this joining table. We'll spin through the given IDs, checking to see
		// if they exist in the array of current ones, and if not we will insert.
		$current = $this->newPivotQuery()->lists($this->otherKey);

		$records = $this->formatSyncList($ids);

		$detach = array_diff($current, array_keys($records));

		// Next, we will take the differences of the currents and given IDs and detach
		// all of the entities that exist in the "current" array but are not in the
		// the array of the IDs given to the method which will complete the sync.
		if ($detaching && count($detach) > 0)
		{
			$this->detach($detach);

			$changes['detached'] = (array) array_map(function($v) { return (int) $v; }, $detach);
		}

		// Now we are finally ready to attach the new records. Note that we'll disable
		// touching until after the entire operation is complete so we don't fire a
		// ton of touch operations until we are totally done syncing the records.
		$changes = array_merge(
			$changes, $this->attachNew($records, $current, false)
		);

		if (count($changes['attached']) || count($changes['updated']))
		{
			$this->touchIfTouching();
		}

		return $changes;
	}
797629
protected function getObjectReferencesByIds(ObjectManager $objectManager, $className, array $ids)
    {
        $entities = [];

        foreach ($ids as $id) {
            /** @var EntityManager $objectManager */
            $entities[] = $objectManager->getReference($className, $id);
        }

        return $entities;
    }
411733
public function several(array $ids)
    {
        $results = [];

        foreach ($ids as $cacheId) {
            if ($this->cache->test($cacheId)) {
                $results[$cacheId] = $this->cache->load($cacheId);
            }

        }

        return $results;
    }
165218
public function detach(Model $model, $relation, $ids = array(), $touch = true)
    {
        return $model->{$relation}()->detach($ids, $touch);
    }
1278430
public function syncTags($tags, bool $detaching = true)
    {
        $this->tags()->sync($this->parseTags($tags, null, null, true), $detaching);

        return $this;
    }
162589
public function batchDelete($ids) {
        $requests = [];

        foreach ($ids as $id) {
            $requests[] = [
                'method' => 'monitoring.livestatus.delete',
                'params' => [
                    'id' => $id
                ]
            ];
        }

        $result = $this->api->batchRequest($requests);

        foreach ($result as $tag) {
            // Do not check 'id' because in a batch request it is always NULL:
            if (!array_key_exists('success', $tag) ||
                $tag['success'] !== true) {
                if (array_key_exists('message', $tag)) {
                    throw new RuntimeException(sprintf('Bad result: %s', $tag['message']));
                } else {
                    throw new RuntimeException('Bad result');
                }
            }
        }

        return $this;
    }
120158
public function removeMany(array $ids) {
		if (! $this->connectionCheckStatus) {
			$this->addServer();
		}
		
		$client = $this->getClient();
		$ids    = array_map([$this, 'prepareId'], $ids);
		
		$result = true;
		
		foreach ($ids as $id) {
			if (! $client->delete($id)) {
				$result = false;
			}
		}
		
		return $result;
	}
236863
public function load($ids)
    {
        settype($ids, 'array');

        $types = $this->getTypes();
        $libraries = $this->getList();

        foreach ($ids as $key => $id) {

            if ($this->isLoaded($id)) {
                unset($ids[$key]);
                continue;
            }

            if (empty($libraries[$id]['type'])) {
                unset($ids[$key]);
                continue;
            }

            if (empty($types[$libraries[$id]['type']]['load'])) {
                unset($ids[$key]);
            }
        }

        $sorted = $this->graph->sort($ids, $libraries);

        if (empty($sorted)) {
            return false;
        }

        foreach ($this->prepareFiles($sorted, $libraries) as $file) {
            require_once $file;
        }

        $this->loaded = array_merge($this->loaded, $sorted);
        return true;
    }
1119493
private function syncModels($relationship, $objects, $team, $detaching)
    {
        if (!Helper::isValidRelationship($relationship)) {
            throw new InvalidArgumentException;
        }

        $objectType = Str::singular($relationship);
        $mappedObjects = [];
        $useTeams = Config::get('laratrust.use_teams');
        $team = $useTeams ? Helper::getIdFor($team, 'team') : null;

        foreach ($objects as $object) {
            if ($useTeams && $team) {
                $mappedObjects[Helper::getIdFor($object, $objectType)] = [Helper::teamForeignKey() => $team];
            } else {
                $mappedObjects[] = Helper::getIdFor($object, $objectType);
            }
        }

        $relationshipToSync = $this->$relationship();

        if ($useTeams && $team) {
            $relationshipToSync->wherePivot(Helper::teamForeignKey(), $team);
        }

        $result = $relationshipToSync->sync($mappedObjects, $detaching);

        $this->flushCache();
        $this->fireLaratrustEvent("{$objectType}.synced", [$this, $result, $team]);

        return $this;
    }
1044059
public function detach($ids = array(), $touch = true)
    {
        if ($ids instanceof Model) $ids = (array) $ids->getKey();

        $query = $this->newPivotQuery();

        $ids = (array) $ids;

        if (count($ids) > 0) {
            $query->whereIn($this->otherKey, (array) $ids);
        }

        if ($touch) $this->touchIfTouching();

        $results = $query->delete();

        return $results;
    }
1190822
protected function createAttachRecords($ids, array $attributes)
    {
        $records = [];

        $timed = in_array($this->createdAt(), $this->pivotColumns);

        // To create the attachment records, we will simply spin through the IDs given
        // and create a new record to insert for each ID. Each ID may actually be a
        // key in the array, with extra attributes to be placed in other columns.
        foreach ($ids as $key => $value) {
            $records[] = $this->attacher($key, $value, $attributes, $timed);
        }

        return $records;
    }
1100492
public function getListByIds($ids, array $additionalFields = array())
    {
        return $this->getInternalList(
            'region/get',
            'Region',
            array(
                'id' => self::getArray($ids),
                'fields' => self::getArray($additionalFields)
            )
        );
    }
669815
public function getMany(array $ids) {
		$result = $this->getBackend()->getMany($ids);
		
		if (! empty($result)) {
			return array_map('json_decode', $result);
		}
		
		return $result;
	}
67892
public function sync($ids, $detaching = true)
    {
        $changes = [
            'attached' => [],
            'detached' => [],
            'updated'  => [],
        ];

        $pk = $this->parent->getPk();

        $current = $this->pivot
            ->where($this->localKey, $this->parent->$pk)
            ->column($this->foreignKey);

        $records = [];

        foreach ($ids as $key => $value) {
            if (!is_array($value)) {
                $records[$value] = [];
            } else {
                $records[$key] = $value;
            }
        }

        $detach = array_diff($current, array_keys($records));

        if ($detaching && count($detach) > 0) {
            $this->detach($detach);
            $changes['detached'] = $detach;
        }

        foreach ($records as $id => $attributes) {
            if (!in_array($id, $current)) {
                $this->attach($id, $attributes);
                $changes['attached'][] = $id;
            } elseif (count($attributes) > 0 && $this->attach($id, $attributes)) {
                $changes['updated'][] = $id;
            }
        }

        return $changes;
    }
99064
public function sync(Model $model, $relation, $ids, $detaching = true)
    {
        return $model->{$relation}()->sync($ids, $detaching);
    }
507280
public function findByIds(array $ids)
    {
        $entities = [];

        for ($i = 0; $i < count($this->registries); $i++) {
            /** @var RegistryInterface $registry */
            $registry = $this->registries[ $i ];
            $found = $registry->findByKeys($ids);
            $entities = array_merge($entities, $found);

            $this->updateRegistries($found, $i - 1);

            if (count($entities) === count($ids)) {
                break;
            }
        }

        return $entities;
    }
1261020
public function selectByIds(array $ids = array())
    {
        if (empty($ids)) {
            return array();
        }

        $ids = array_map('intval', $ids);

        $sql = $this->getSelectQueryByIds($ids);

        $resultSet = $this->db->fetchAll($sql);

        return $this->implementVOs($resultSet);
    }