Select the related ids to attach.

@param  array[] $insertedPKs
@return array
161322
protected function pickRelatedIds(array $insertedPKs)
    {
        return $this->generator->randomElements($insertedPKs[$this->relatedClass], $this->getQuantity($insertedPKs));
    }
1083920
public function findRelatedEntries($entry_id, $parent_field_id)
    {
        try {
            $ids = Symphony::Database()->fetchCol('entry_id', sprintf("
                SELECT `entry_id`
                FROM `tbl_entries_data_%d`
                WHERE `relation_id` = %d
                AND `entry_id` IS NOT NULL
            ", $this->get('id'), $entry_id));
        } catch (Exception $e) {
            return array();
        }

        return $ids;
    }
971042
protected function loadRelated(): array
    {
        $innerKey = $this->parent->getField($this->key(Record::INNER_KEY));
        if (empty($innerKey)) {
            return [];
        }

        //Work with pre-build query
        $query = $this->createQuery($innerKey);

        //Use custom node to parse data
        $node = new PivotedRootNode(
            $this->schema[Record::RELATION_COLUMNS],
            $this->schema[Record::PIVOT_COLUMNS],
            $this->schema[Record::OUTER_KEY],
            $this->schema[Record::THOUGHT_INNER_KEY],
            $this->schema[Record::THOUGHT_OUTER_KEY]
        );

        $iterator = $query->getIterator();
        foreach ($iterator as $row) {
            //Time to parse some data
            $node->parseRow(0, $row);
        }

        //Memory free
        $iterator->close();

        return $node->getResult();
    }
669185
function getPrimaryKeyValues() {
		$arr = array();
		$pks = static::$_primaryKeys;

		foreach ($pks as &$pk) {
			$arr[] = $this->{"get$pk"}();
		}

		return $arr;
	}
397827
public static function getAssociations($pk, $extension = 'com_content')
	{
		$langAssociations = JLanguageAssociations::getAssociations($extension, '#__categories', 'com_categories.item', $pk, 'id', 'alias', '');
		$associations = array();

		foreach ($langAssociations as $langAssociation)
		{
			$associations[$langAssociation->language] = $langAssociation->id;
		}

		return $associations;
	}
161148
public function getRelationsFor($respondentId, $patientNr = null, $organizationId = null, $onlyActive = true)
    {
        static $relationsCache = array();

        if (is_null($respondentId)) {
            $respondentId = $this->loader->getUtil()->getDbLookup()->getRespondentId($patientNr, $organizationId);
        }

        if (!array_key_exists($respondentId, $relationsCache)) {
            $relations = array();
            $filter = array('grr_id_respondent'=>$respondentId);
            if ($onlyActive) {
                $filter['grr_active'] = 1;
            }
            $rawRelations = $this->load($filter);
            foreach ($rawRelations as $relation)
            {
                $relations[$relation['grr_id']] = join(' ', array($relation['grr_type'], $relation['grr_first_name'], $relation['grr_last_name']));
            }
            $relationsCache[$respondentId] = $relations;
        }

        return $relationsCache[$respondentId];
    }
1307595
public function getRelatedItemCallIds($deliveryResultIdentifier)
    {
        $keys = $this->getPersistence()->keys(self::PREFIX_CALL_ID . $deliveryResultIdentifier . '.*');
        array_walk($keys, 'self::subStrPrefix', self::PREFIX_CALL_ID);

        return $keys;
    }
1085464
public function get_related_data( $post_id ) {
		if ( ! isset( $this->_related_data[ $post_id ] ) ) {
			$table = $this->get_related_table_name();
			$data  = $this->app->db->select_row( $table, [
				'post_id' => $post_id,
			] );
			if ( empty( $data ) ) {
				$data = false;
			} else {
				$post = get_post( $post_id );
				if ( empty( $post ) || $post->post_type != $this->get_post_type() ) {
					$data = false;
				} else {
					$data = $this->filter_item( $this->set_post_data( $data, $post ) );
				}
			}

			$this->_related_data[ $post_id ] = $data;
		}

		return $this->_related_data[ $post_id ];
	}
1072558
public function getIncludedRelationships(string $baseRelationshipPath): array
    {
        if ($this->includedRelationships === null) {
            $this->setIncludedRelationships();
        }

        if (isset($this->includedRelationships[$baseRelationshipPath])) {
            return array_values($this->includedRelationships[$baseRelationshipPath]);
        }

        return [];
    }
1343189
protected function getAssignedAddOns() {
        if (!$this->_assignedAddOns) {
            $this->_assignedAddOns = new AssignedAddOnList(
                $this->version,
                $this->solution['accountSid'],
                $this->solution['sid']
            );
        }

        return $this->_assignedAddOns;
    }
1153960
protected function getResultsByRelatedKey($relations)
	{
		$resultsByRelatedKey = [];

		foreach ($relations as $relation)
		{
			if (!isset($resultsByRelatedKey[$relation->{$this->associativeLocal}]))
			{
				$resultsByRelatedKey[$relation->{$this->associativeLocal}] = new Rows;
			}

			$resultsByRelatedKey[$relation->{$this->associativeLocal}]->push($relation);
		}

		return $resultsByRelatedKey;
	}
677682
protected function pickMorphOwner(array $insertedPKs, $alwaysAssociate)
    {
        $owners = $this->populator->getMorphToClasses(get_class($this->model));

        // We'll share the chosen owner between the foreign key and morph type closures
        // by saving it in $this until the next call to this method.
        if ($this->morphOwner === false) {
            if (!$alwaysAssociate && rand(0, 1)) {
                return $this->morphOwner = null;
            }

            // Filters the owning classes that have been added to Populator.
            $owners = array_filter($owners, function ($owner) use ($insertedPKs) {
                return isset($insertedPKs[$owner]);
            });

            return $this->morphOwner = $this->generator->randomElement($owners);
        }

        return tap($this->morphOwner, function () {
            // We'll unset the picked owner,
            // so it will be picked again randomly when the next model is created.
            $this->morphOwner = false;
        });
    }
1131280
public function getAssociations($post_id = null)
    {
        $oConfig       = Factory::service('Config');
        $oDb           = Factory::service('Database');
        $_associations = $oConfig->item('blog_post_associations');

        if (!$_associations) {
            return array();
        }

        // --------------------------------------------------------------------------

        foreach ($_associations as &$assoc) {

            /**
             * Fetch the association data from the source, fail ungracefully - the dev
             * should have this configured correctly.
             *
             * Fetch current associations if a post_id has been supplied
             */

            if ($post_id) {

                $oDb->where('post_id', $post_id);
                $assoc->current = $oDb->get($assoc->target)->result();

            } else {

                $assoc->current = array();
            }

            //  Fetch the raw data
            $oDb->select($assoc->source->id . ' id, ' . $assoc->source->label . ' label');
            $oDb->order_by('label');

            if (isset($assoc->source->where) && $assoc->source->where) {

                $oDb->where($assoc->source->where);
            }

            $assoc->data = $oDb->get($assoc->source->table)->result();
        }

        return $_associations;
    }
328515
public function addSelectRelected(array $fields)
    {
        if (is_bool($this->selectRelected)) {
            $relatedFields = [];
        } else {
            $relatedFields = $this->selectRelected;
        }

        // we need the path to follow
        //
        //array(
        //  "order" => array(
        //    "buyer" => array()
        //  )
        //  "product" => array()
        //)
        foreach ($fields as $field) {
            $names = StringHelper::split(BaseLookup::$lookupPattern, $field);
            // we use by reference so that we assigned the values back to the original array
            $d = &$relatedFields;
            foreach ($names as $name) {
                $d = &$d[$name];
                if (empty($d)) {
                    $d = [];
                }
            }
        }
        $this->selectRelected = $relatedFields;
    }
932995
protected function _getIds(array $ids, $primaryKey = self::PRIMARY_KEY)
    {
        $return = [];
        foreach ($ids as $id => $value) {
            if (is_array($value) && is_int($id) && (int) $value[$primaryKey] === 1) {
                $return[$id] = $id;
            }
        }

        return $return;
    }
1216929
public function relations($embedded = false)
    {
        $result = [];
        foreach ($this->_relations as $field => $config) {
            if (!$config['embedded'] || $embedded) {
                $result[] = $field;
            }
        }
        return $result;
    }
479609
public function getSelectedRelatedProducts()
    {
        $products = [];
        foreach ($this->getPost()->getRelatedProducts() as $product) {
            $products[$product->getId()] = ['position' => 0];
        }

        return $products;
    }