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());
 }
 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;
 }