src/Schema.php
public function getRelations($many = -1)
    {
        $results = [];
        if (!isset($this->data['relations'])
            || empty($this->data['relations'])
        ) {
            return $results;
        }

        $table = $this->getName();
        $primary = $this->getPrimaryFieldName();

        foreach ($this->data['relations'] as $relation) {
            if (is_numeric($many) && $many != -1 && $many != $relation['many']) {
                continue;
            }

            //case for getting a specific relation
            if (!is_numeric($many) && $relation['name'] !== $many) {
                continue;
            }

            $name = $table . '_' . $relation['name'];

            $results[$name] = [];

            try {
                $results[$name] = Schema::i($relation['name'])->getAll(false);
            } catch (Exception $e) {
                //this is not a registered schema
                //lets make a best guess
                $results[$name]['name'] = $relation['name'];
                $results[$name]['singular'] = ucfirst($relation['name']);
                $results[$name]['plural'] = $results[$name]['singular'] . 's';
                $results[$name]['primary'] =  $relation['name'] . '_id';
            }

            $results[$name]['table'] = $name;
            $results[$name]['primary1'] = $primary;
            $results[$name]['primary2'] = $results[$name]['primary'];
            $results[$name]['many'] = $relation['many'];
            $results[$name]['source'] = $this->getAll(false);

            //case for relating to itself ie. post_post
            if ($table === $relation['name']) {
                $results[$name]['primary1'] .= '_1';
                $results[$name]['primary2'] .= '_2';
            }

            //case for getting a specific relation
            if (!is_numeric($many) && $relation['name'] === $many) {
                return $results[$name];
            }
        }

        return $results;
    }
public function getRelations($many = -1)
    {
        $results = [];
        if (!isset($this->data['relations'])
            || empty($this->data['relations'])
        ) {
            return $results;
        }

        $table = $this->getName();
        $primary = $this->getPrimaryFieldName();

        foreach ($this->data['relations'] as $relation) {
            if (is_numeric($many) && $many != -1 && $many != $relation['many']) {
                continue;
            }

            //case for getting a specific relation
            if (!is_numeric($many) && $relation['name'] !== $many) {
                continue;
            }

            $name = $table . '_' . $relation['name'];

            $results[$name] = [];

            try {
                $results[$name] = Schema::i($relation['name'])->getAll(false);
            } catch (Exception $e) {
                //this is not a registered schema
                //lets make a best guess
                $results[$name]['name'] = $relation['name'];
                $results[$name]['singular'] = ucfirst($relation['name']);
                $results[$name]['plural'] = $results[$name]['singular'] . 's';
                $results[$name]['primary'] =  $relation['name'] . '_id';
            }

            $results[$name]['table'] = $name;
            $results[$name]['primary1'] = $primary;
            $results[$name]['primary2'] = $results[$name]['primary'];
            $results[$name]['many'] = $relation['many'];
            $results[$name]['source'] = $this->getAll(false);

            //case for relating to itself ie. post_post
            if ($table === $relation['name']) {
                $results[$name]['primary1'] .= '_1';
                $results[$name]['primary2'] .= '_2';
            }

            //case for getting a specific relation
            if (!is_numeric($many) && $relation['name'] === $many) {
                return $results[$name];
            }
        }

        return $results;
    }
public function getRelations ( $ many = - 1 ) { $ results = [ ] ; if ( ! isset ( $ this -> data [ 'relations' ] ) || empty ( $ this -> data [ 'relations' ] ) ) { return $ results ; } $ table = $ this -> getName ( ) ; $ primary = $ this -> getPrimaryFieldName ( ) ; foreach ( $ this -> data [ 'relations' ] as $ relation ) { if ( is_numeric ( $ many ) && $ many != - 1 && $ many != $ relation [ 'many' ] ) { continue ; } //case for getting a specific relation if ( ! is_numeric ( $ many ) && $ relation [ 'name' ] !== $ many ) { continue ; } $ name = $ table . '_' . $ relation [ 'name' ] ; $ results [ $ name ] = [ ] ; try { $ results [ $ name ] = Schema :: i ( $ relation [ 'name' ] ) -> getAll ( false ) ; } catch ( Exception $ e ) { //this is not a registered schema //lets make a best guess $ results [ $ name ] [ 'name' ] = $ relation [ 'name' ] ; $ results [ $ name ] [ 'singular' ] = ucfirst ( $ relation [ 'name' ] ) ; $ results [ $ name ] [ 'plural' ] = $ results [ $ name ] [ 'singular' ] . 's' ; $ results [ $ name ] [ 'primary' ] = $ relation [ 'name' ] . '_id' ; } $ results [ $ name ] [ 'table' ] = $ name ; $ results [ $ name ] [ 'primary1' ] = $ primary ; $ results [ $ name ] [ 'primary2' ] = $ results [ $ name ] [ 'primary' ] ; $ results [ $ name ] [ 'many' ] = $ relation [ 'many' ] ; $ results [ $ name ] [ 'source' ] = $ this -> getAll ( false ) ; //case for relating to itself ie. post_post if ( $ table === $ relation [ 'name' ] ) { $ results [ $ name ] [ 'primary1' ] .= '_1' ; $ results [ $ name ] [ 'primary2' ] .= '_2' ; } //case for getting a specific relation if ( ! is_numeric ( $ many ) && $ relation [ 'name' ] === $ many ) { return $ results [ $ name ] ; } } return $ results ; }
Returns relational data

@param int $many

@return array
Returns relational data