예제 #1
0
 /**
  * @param $onTableAliasName
  * @param bool $canUseFromJoins
  * @return null|string
  */
 protected function resolveJoinsForAttributeOnDifferentModel($onTableAliasName, $canUseFromJoins = true)
 {
     assert('is_string($onTableAliasName)');
     assert('is_bool($canUseFromJoins)');
     if ($this->modelAttributeToDataProviderAdapter->isRelation()) {
         return $this->resolveJoinsForAttributeOnDifferentModelThatIsARelation($onTableAliasName, $canUseFromJoins);
     } else {
         return $this->resolveJoinsForAttributeOnDifferentModelThatIsNotARelation($onTableAliasName, $canUseFromJoins);
     }
 }
 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());
 }
예제 #3
0
 public static function resolveSortAttributeColumnName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter)
 {
     if ($modelAttributeToDataProviderAdapter->isRelation()) {
         if (!$modelAttributeToDataProviderAdapter->hasRelatedAttribute()) {
             throw new NotSupportedException();
         }
         assert('$modelAttributeToDataProviderAdapter->getRelationType() != RedBeanModel::MANY_MANY');
         $onTableAliasName = self::resolveShouldAddFromTableAndGetAliasName($modelAttributeToDataProviderAdapter, $joinTablesAdapter);
         $tableAliasName = self::resolveJoinsForRelatedAttributeAndGetRelationAttributeTableAliasName($modelAttributeToDataProviderAdapter, $joinTablesAdapter, $onTableAliasName);
         $resolvedSortColumnName = $modelAttributeToDataProviderAdapter->getRelatedAttributeColumnName();
     } else {
         $tableAliasName = self::resolveShouldAddFromTableAndGetAliasName($modelAttributeToDataProviderAdapter, $joinTablesAdapter);
         $resolvedSortColumnName = $modelAttributeToDataProviderAdapter->getColumnName();
     }
     $sort = DatabaseCompatibilityUtil::quoteString($tableAliasName);
     $sort .= '.';
     $sort .= DatabaseCompatibilityUtil::quoteString($resolvedSortColumnName);
     return $sort;
 }