private function belongsToMany()
    {
        // Return if there are no relationships of that type
        if (!isset($this->relationships['belongsToMany']) || empty($this->relationships['belongsToMany'])) {
            return $this;
        }

        // Group by primary key
        $this->db()->groupBy($this->table . '.' . $this->primaryKey);

        // Iterate relationships
        foreach ($this->relationships['belongsToMany'] as $join) {

            // Perform join
            $this->db()->join($join['pivot'], $this->primaryKey, '=', $join['localKey']);

            // Add related columns to select
            $column = 'GROUP_CONCAT(' . $join['pivot'] . '.' . $join['foreignKey'] . ') as concat_' . $join['alias'];
            $this->db()->addSelect($column);
        }

        // Return model instance
        return $this;
    }
private function belongsToMany()
    {
        // Return if there are no relationships of that type
        if (!isset($this->relationships['belongsToMany']) || empty($this->relationships['belongsToMany'])) {
            return $this;
        }

        // Group by primary key
        $this->db()->groupBy($this->table . '.' . $this->primaryKey);

        // Iterate relationships
        foreach ($this->relationships['belongsToMany'] as $join) {

            // Perform join
            $this->db()->join($join['pivot'], $this->primaryKey, '=', $join['localKey']);

            // Add related columns to select
            $column = 'GROUP_CONCAT(' . $join['pivot'] . '.' . $join['foreignKey'] . ') as concat_' . $join['alias'];
            $this->db()->addSelect($column);
        }

        // Return model instance
        return $this;
    }
private function belongsToMany ( ) { // Return if there are no relationships of that type if ( ! isset ( $ this -> relationships [ 'belongsToMany' ] ) || empty ( $ this -> relationships [ 'belongsToMany' ] ) ) { return $ this ; } // Group by primary key $ this -> db ( ) -> groupBy ( $ this -> table . '.' . $ this -> primaryKey ) ; // Iterate relationships foreach ( $ this -> relationships [ 'belongsToMany' ] as $ join ) { // Perform join $ this -> db ( ) -> join ( $ join [ 'pivot' ] , $ this -> primaryKey , '=' , $ join [ 'localKey' ] ) ; // Add related columns to select $ column = 'GROUP_CONCAT(' . $ join [ 'pivot' ] . '.' . $ join [ 'foreignKey' ] . ') as concat_' . $ join [ 'alias' ] ; $ this -> db ( ) -> addSelect ( $ column ) ; } // Return model instance return $ this ; }
Resolves many to many relationships

@return object Model instance
Resolves many to many relationships