Bolt\Storage\Entity\ContentRelationTrait::getRelation PHP Method

getRelation() public method

Gets one or more related records.
public getRelation ( string $filterContentType = null, array $options = [] ) : Content[]
$filterContentType string ContentType to filter returned results on
$options array A set of 'WHERE' options to apply to the filter Backward compatability note: The $options parameter used to be $filterid, an integer.
return Bolt\Legacy\Content[]
    public function getRelation($filterContentType = null, $options = [])
    {
        if (empty($this->relation)) {
            return false;
            // nothing to do here.
        }
        // Backwards compatibility: If '$options' is a string, assume we passed an id
        if (!is_array($options)) {
            $options = ['id' => $options];
        }
        $records = [];
        foreach ($this->relation as $contenttype => $ids) {
            if (!empty($filterContentType) && $contenttype != $filterContentType) {
                continue;
                // Skip other contenttypes, if we requested a specific type.
            }
            $params = ['hydrate' => true];
            $where = ['id' => implode(' || ', $ids)];
            $dummy = false;
            // If there were other options add them to the 'where'. We potentially overwrite the 'id' here.
            if (!empty($options)) {
                foreach ($options as $option => $value) {
                    $where[$option] = $value;
                }
            }
            // Only get published items, unless specifically stated otherwise.
            if (!isset($where['status'])) {
                $where['status'] = 'published';
            }
            $tempResult = $this->app['storage']->getContent($contenttype, $params, $dummy, $where);
            if (empty($tempResult)) {
                continue;
                // Go ahead if content not found.
            }
            // Variable $temp_result can be an array of object.
            if (is_array($tempResult)) {
                $records = array_merge($records, $tempResult);
            } else {
                $records[] = $tempResult;
            }
        }
        return $records;
    }