예제 #1
0
 /**
  * @param $onTableAliasName
  * @return null|string
  */
 protected function resolveJoinsForForARelationAttributeThatIsAHasOne($onTableAliasName)
 {
     assert('is_string($onTableAliasName)');
     $tableJoinIdName = 'id';
     $onTableJoinIdName = $this->modelAttributeToDataProviderAdapter->getColumnName();
     $onTableAliasName = $this->joinTablesAdapter->addLeftTableAndGetAliasName($this->modelAttributeToDataProviderAdapter->getRelationTableName(), $onTableJoinIdName, $onTableAliasName, $tableJoinIdName);
     return $onTableAliasName;
 }
 /**
  * @param RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter
  * @return string
  */
 protected static function resolveSortColumnName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter)
 {
     if ($modelAttributeToDataProviderAdapter->hasRelatedAttribute()) {
         return $modelAttributeToDataProviderAdapter->getRelatedAttributeColumnName();
     } else {
         return $modelAttributeToDataProviderAdapter->getColumnName();
     }
 }
 public function testAllMethodsOnAttributeOnSameModelAndRelatedAttribute()
 {
     $adapter = new RedBeanModelAttributeToDataProviderAdapter('I', 'j', 'jMember');
     $this->assertEquals('I', $adapter->getModelClassName());
     $this->assertEquals('j', $adapter->getAttribute());
     $this->assertEquals('jMember', $adapter->getRelatedAttribute());
     $this->assertEquals('i', $adapter->getModelTableName());
     $this->assertEquals('I', $adapter->getAttributeModelClassName());
     $this->assertEquals('i', $adapter->getAttributeTableName());
     $this->assertEquals('j_id', $adapter->getColumnName());
     $this->assertTrue($adapter->isRelation());
     $this->assertTrue($adapter->hasRelatedAttribute());
     $this->assertEquals('J', $adapter->getRelationModelClassName());
     $this->assertEquals('J', $adapter->getRelatedAttributeModelClassName());
     $this->assertEquals('j', $adapter->getRelationTableName());
     $this->assertEquals('j', $adapter->getRelatedAttributeTableName());
     $this->assertEquals('jmember', $adapter->getRelatedAttributeColumnName());
     $this->assertFalse($adapter->isRelatedAttributeRelation());
 }
 /**
  * @param string $modelClassName
  * @param array $concatedAttributeNames
  * @param RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter
  * @param null | string $onTableAliasName
  * @return array
  */
 protected static function makeTableAliasAndColumnNamesForNonRelatedConcatedAttributes($modelClassName, $concatedAttributeNames, $joinTablesAdapter, $onTableAliasName = null)
 {
     assert('is_string($modelClassName)');
     assert('is_array($concatedAttributeNames) && count($concatedAttributeNames) == 2');
     assert('$joinTablesAdapter instanceof RedBeanModelJoinTablesQueryAdapter');
     assert('is_string($onTableAliasName) || $onTableAliasName == null');
     $tableAliasAndColumnNames = array();
     foreach ($concatedAttributeNames as $attributeName) {
         $modelAttributeToDataProviderAdapter = new RedBeanModelAttributeToDataProviderAdapter($modelClassName, $attributeName);
         $builder = new ModelWhereAndJoinBuilder($modelAttributeToDataProviderAdapter, $joinTablesAdapter, true);
         $tableAliasName = $builder->resolveJoins($onTableAliasName, self::resolveCanUseFromJoins($onTableAliasName));
         $tableAliasAndColumnNames[] = array($tableAliasName, $modelAttributeToDataProviderAdapter->getColumnName());
     }
     return $tableAliasAndColumnNames;
 }
예제 #5
0
 protected static function resolveJoinsForRelatedAttributeAndGetRelationAttributeTableAliasName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter, $onTableAliasName)
 {
     assert('$modelAttributeToDataProviderAdapter->getRelationType() != RedBeanModel::MANY_MANY');
     assert('is_string($onTableAliasName)');
     if ($modelAttributeToDataProviderAdapter->getRelationType() == RedBeanModel::HAS_MANY || $modelAttributeToDataProviderAdapter->getRelationType() == RedBeanModel::HAS_MANY_BELONGS_TO) {
         $onTableJoinIdName = 'id';
         $tableJoinIdName = $onTableAliasName . '_id';
         //HAS_MANY have the potential to produce more than one row per model, so we need
         //to signal the query to be distinct.
         if ($modelAttributeToDataProviderAdapter->getRelationType() == RedBeanModel::HAS_MANY) {
             $joinTablesAdapter->setSelectDistinctToTrue();
         }
     } elseif ($modelAttributeToDataProviderAdapter->getRelationType() == RedBeanModel::HAS_ONE_BELONGS_TO) {
         $tableJoinIdName = $onTableAliasName . '_id';
         $onTableJoinIdName = 'id';
     } else {
         $onTableJoinIdName = $modelAttributeToDataProviderAdapter->getColumnName();
         $tableJoinIdName = 'id';
     }
     $relationTableAliasName = $joinTablesAdapter->addLeftTableAndGetAliasName($modelAttributeToDataProviderAdapter->getRelationTableName(), $onTableJoinIdName, $onTableAliasName, $tableJoinIdName);
     $relationAttributeTableAliasName = $relationTableAliasName;
     //the second left join check being performed is if you
     //are in a contact filtering on related account email as an example.
     if ($modelAttributeToDataProviderAdapter->getRelatedAttributeModelClassName() != $modelAttributeToDataProviderAdapter->getRelationModelClassName()) {
         $relationAttributeTableName = $modelAttributeToDataProviderAdapter->getRelatedAttributeTableName();
         //Handling special scenario for casted down Person.  Todo: Automatically determine a
         //casted down scenario instead of specifically looking for Person.
         if ($modelAttributeToDataProviderAdapter->getRelatedAttributeModelClassName() == 'Person') {
             $onTableJoinIdName = "{$relationAttributeTableName}_id";
         } elseif (get_parent_class($modelAttributeToDataProviderAdapter->getRelationModelClassName()) == $modelAttributeToDataProviderAdapter->getRelatedAttributeModelClassName()) {
             $onTableJoinIdName = "{$relationAttributeTableName}_id";
         } else {
             $onTableJoinIdName = "{$modelAttributeToDataProviderAdapter->getRelatedAttributeColumnName()}" . "_{$relationAttributeTableName}_id";
         }
         $relationAttributeTableAliasName = $joinTablesAdapter->addLeftTableAndGetAliasName($relationAttributeTableName, $onTableJoinIdName, $relationTableAliasName);
     }
     return $relationAttributeTableAliasName;
 }