Attila/core/Model.php
public function hasManyToMany($sPrimaryKeyName, $sEntityJoinName, $sForeignKeyName, $sNamespaceEntity, $sManyToManyKeyName, $sManyToManyTableName, array $aOptions = array())
	{
	    $this->_ahasMany[$sEntityJoinName] = function($mParameters = null) use ($sPrimaryKeyName, $sEntityJoinName, $sForeignKeyName, $sManyToManyKeyName, $sManyToManyTableName, $sNamespaceEntity)
	    {
	        if (!isset($this->$sEntityJoinName)) {
	             
	            $oOrm = new Orm;
	             
	            $oOrm->select(array('*'))
	                 ->from($sEntityJoinName);
	    
	            if ($mParameters) {
	                 
	                $aWhere[$sForeignKeyName] = $mParameters;
	            }
	            else {
	                 
	                $sMethodName = 'get_'.$sPrimaryKeyName;
	                $aWhere[$sForeignKeyName] = $this->$sMethodName();
	            }
	    
	    
	            $this->$sEntityJoinName = $oOrm->where($aWhere)
	                                           ->load(false, $sNamespaceEntity.'\\');
	        }
	        
	        $aResults = array();
	        
	        foreach ($this->$sEntityJoinName as $iKey => $oOne) {
	            
	            $oOrm = new Orm;
	            
	            $oOrm->select(array('*'))
	                 ->from($sManyToManyTableName);
	             
	            if ($mParameters) {
	            
	                $aWhere[$sManyToManyKeyName] = $mParameters;
	            }
	            else {
	            
	                $sMethodName = 'get_'.$sManyToManyKeyName;
	                $aWhere[$sManyToManyKeyName] = $this->$sMethodName();
	            }
	             
	             
	            $aResults[] = $oOrm->where($aWhere)
	                               ->load(false, $sNamespaceEntity.'\\');
	        }
	         
	        return $aResults;
	    };
	}
public function hasManyToMany($sPrimaryKeyName, $sEntityJoinName, $sForeignKeyName, $sNamespaceEntity, $sManyToManyKeyName, $sManyToManyTableName, array $aOptions = array())
	{
	    $this->_ahasMany[$sEntityJoinName] = function($mParameters = null) use ($sPrimaryKeyName, $sEntityJoinName, $sForeignKeyName, $sManyToManyKeyName, $sManyToManyTableName, $sNamespaceEntity)
	    {
	        if (!isset($this->$sEntityJoinName)) {
	             
	            $oOrm = new Orm;
	             
	            $oOrm->select(array('*'))
	                 ->from($sEntityJoinName);
	    
	            if ($mParameters) {
	                 
	                $aWhere[$sForeignKeyName] = $mParameters;
	            }
	            else {
	                 
	                $sMethodName = 'get_'.$sPrimaryKeyName;
	                $aWhere[$sForeignKeyName] = $this->$sMethodName();
	            }
	    
	    
	            $this->$sEntityJoinName = $oOrm->where($aWhere)
	                                           ->load(false, $sNamespaceEntity.'\\');
	        }
	        
	        $aResults = array();
	        
	        foreach ($this->$sEntityJoinName as $iKey => $oOne) {
	            
	            $oOrm = new Orm;
	            
	            $oOrm->select(array('*'))
	                 ->from($sManyToManyTableName);
	             
	            if ($mParameters) {
	            
	                $aWhere[$sManyToManyKeyName] = $mParameters;
	            }
	            else {
	            
	                $sMethodName = 'get_'.$sManyToManyKeyName;
	                $aWhere[$sManyToManyKeyName] = $this->$sMethodName();
	            }
	             
	             
	            $aResults[] = $oOrm->where($aWhere)
	                               ->load(false, $sNamespaceEntity.'\\');
	        }
	         
	        return $aResults;
	    };
	}
public function hasManyToMany ( $ sPrimaryKeyName , $ sEntityJoinName , $ sForeignKeyName , $ sNamespaceEntity , $ sManyToManyKeyName , $ sManyToManyTableName , array $ aOptions = array ( ) ) { $ this -> _ahasMany [ $ sEntityJoinName ] = function ( $ mParameters = null ) use ( $ sPrimaryKeyName , $ sEntityJoinName , $ sForeignKeyName , $ sManyToManyKeyName , $ sManyToManyTableName , $ sNamespaceEntity ) { if ( ! isset ( $ this -> $ sEntityJoinName ) ) { $ oOrm = new Orm ; $ oOrm -> select ( array ( '*' ) ) -> from ( $ sEntityJoinName ) ; if ( $ mParameters ) { $ aWhere [ $ sForeignKeyName ] = $ mParameters ; } else { $ sMethodName = 'get_' . $ sPrimaryKeyName ; $ aWhere [ $ sForeignKeyName ] = $ this -> $ sMethodName ( ) ; } $ this -> $ sEntityJoinName = $ oOrm -> where ( $ aWhere ) -> load ( false , $ sNamespaceEntity . '\\' ) ; } $ aResults = array ( ) ; foreach ( $ this -> $ sEntityJoinName as $ iKey => $ oOne ) { $ oOrm = new Orm ; $ oOrm -> select ( array ( '*' ) ) -> from ( $ sManyToManyTableName ) ; if ( $ mParameters ) { $ aWhere [ $ sManyToManyKeyName ] = $ mParameters ; } else { $ sMethodName = 'get_' . $ sManyToManyKeyName ; $ aWhere [ $ sManyToManyKeyName ] = $ this -> $ sMethodName ( ) ; } $ aResults [ ] = $ oOrm -> where ( $ aWhere ) -> load ( false , $ sNamespaceEntity . '\\' ) ; } return $ aResults ; } ; }
create a join in many to many

@access public
@param string $sPrimaryKeyName
@param string $sEntityJoinName
@param string $sForeignKeyName
@param string $sNamespaceEntity
@param unknown $sManyToManyKeyName
@param unknown $sManyToManyTableName
@param array $aOptions
@return object
create a join in many to many