public function leftJoin($secondStore,$matching)
    {
        $dstore = new DataStore;
        // join with other datasource to produce new one with above condition
        $firstKeys = array_keys($matching);
        $secondKeys = array_values($matching);
        
        
        $firstMaps = $this->_mapKeyIndex($this->rows, $firstKeys);
        $secondMaps = $this->_mapKeyIndex($secondStore->all(), $secondKeys);

        $secondNullRow = array();
        foreach ($secondStore->first() as $k=>$v) {
            $secondNullRow[$k] = null;
        }
        
        foreach ($firstMaps as $key=>$indices) {
            foreach ($indices as $i) {
                if (isset($secondMaps[$key])) {
                    foreach ($secondMaps[$key] as $j) {
                        $dstore->push(
                            array_merge(
                                $this->rows[$i],
                                $secondStore->get($j)
                            )
                        );
                    }
                } else {
                    $dstore->push(
                        array_merge(
                            $this->rows[$i],
                            $secondNullRow
                        )
                    );
                }
            }
        }

        $columnMeta = array_merge(
            $this->metaData["columns"], 
            $secondStore->meta()["columns"]
        );
        $dstore->meta(array("columns"=>$columnMeta));
        return $dstore;
    }
public function leftJoin($secondStore,$matching)
    {
        $dstore = new DataStore;
        // join with other datasource to produce new one with above condition
        $firstKeys = array_keys($matching);
        $secondKeys = array_values($matching);
        
        
        $firstMaps = $this->_mapKeyIndex($this->rows, $firstKeys);
        $secondMaps = $this->_mapKeyIndex($secondStore->all(), $secondKeys);

        $secondNullRow = array();
        foreach ($secondStore->first() as $k=>$v) {
            $secondNullRow[$k] = null;
        }
        
        foreach ($firstMaps as $key=>$indices) {
            foreach ($indices as $i) {
                if (isset($secondMaps[$key])) {
                    foreach ($secondMaps[$key] as $j) {
                        $dstore->push(
                            array_merge(
                                $this->rows[$i],
                                $secondStore->get($j)
                            )
                        );
                    }
                } else {
                    $dstore->push(
                        array_merge(
                            $this->rows[$i],
                            $secondNullRow
                        )
                    );
                }
            }
        }

        $columnMeta = array_merge(
            $this->metaData["columns"], 
            $secondStore->meta()["columns"]
        );
        $dstore->meta(array("columns"=>$columnMeta));
        return $dstore;
    }
public function leftJoin ( $ secondStore , $ matching ) { $ dstore = new DataStore ; // join with other datasource to produce new one with above condition $ firstKeys = array_keys ( $ matching ) ; $ secondKeys = array_values ( $ matching ) ; $ firstMaps = $ this -> _mapKeyIndex ( $ this -> rows , $ firstKeys ) ; $ secondMaps = $ this -> _mapKeyIndex ( $ secondStore -> all ( ) , $ secondKeys ) ; $ secondNullRow = array ( ) ; foreach ( $ secondStore -> first ( ) as $ k => $ v ) { $ secondNullRow [ $ k ] = null ; } foreach ( $ firstMaps as $ key => $ indices ) { foreach ( $ indices as $ i ) { if ( isset ( $ secondMaps [ $ key ] ) ) { foreach ( $ secondMaps [ $ key ] as $ j ) { $ dstore -> push ( array_merge ( $ this -> rows [ $ i ] , $ secondStore -> get ( $ j ) ) ) ; } } else { $ dstore -> push ( array_merge ( $ this -> rows [ $ i ] , $ secondNullRow ) ) ; } } } $ columnMeta = array_merge ( $ this -> metaData [ "columns" ] , $ secondStore -> meta ( ) [ "columns" ] ) ; $ dstore -> meta ( array ( "columns" => $ columnMeta ) ) ; return $ dstore ; }
Left join with another datastore on matching keys

Examples

$store1->join($store2,array("id"=>"userId"));

@param DataStore $secondStore Second datastore
@param array     $matching    Matching keys

@return DataStore New datastore containing results.
Left join with another datastore on matching keys