/** * @return mixed */ private function resolveOnTableAliasNameForDerivedRelationViaCastedUpModel() { if ($this->modelAttributeToDataProviderAdapter->isAttributeDerivedRelationViaCastedUpModel()) { $onTableAliasName = $this->modelAttributeToDataProviderAdapter->getModelTableName(); } else { $onTableAliasName = $this->modelAttributeToDataProviderAdapter->getAttributeTableName(); } return $onTableAliasName; }
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()); }
/** * For both non related and related attributes, this method resolves whether a from join is needed. This occurs * for example if a model attribute is castedUp. And that attribute is a relation that needs to be joined in * order to search. Since that attribute is castedUp, the castedUp model needs to be from joined first. This * also applies if the attribute is not a relation and just a member on the castedUp model. In that scenario, * the castedUp model also needs to be joined. * * This methhod assumes if the attribute is not on the base model, that it is casted up not down from it. */ public static function resolveShouldAddFromTableAndGetAliasName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter) { $attributeTableName = $modelAttributeToDataProviderAdapter->getAttributeTableName(); $tableAliasName = $attributeTableName; if ($modelAttributeToDataProviderAdapter->getModelClassName() == 'User' && $modelAttributeToDataProviderAdapter->getAttributeModelClassName() == 'Person') { $modelTableName = $modelAttributeToDataProviderAdapter->getModelTableName(); if (!$joinTablesAdapter->isTableInFromTables('person')) { $personTableName = $attributeTableName; $joinTablesAdapter->addFromTableAndGetAliasName($personTableName, "{$personTableName}_id", $modelTableName); } } elseif ($modelAttributeToDataProviderAdapter->getAttributeModelClassName() != $modelAttributeToDataProviderAdapter->getModelClassName()) { $modelClassName = $modelAttributeToDataProviderAdapter->getModelClassName(); while (get_parent_class($modelClassName) != $modelAttributeToDataProviderAdapter->getAttributeModelClassName()) { $castedDownModelClassName = $modelClassName; $modelClassName = get_parent_class($modelClassName); $castedUpAttributeTableName = $modelClassName::getTableName($modelClassName); if (!$joinTablesAdapter->isTableInFromTables($castedUpAttributeTableName)) { $joinTablesAdapter->addFromTableAndGetAliasName($castedUpAttributeTableName, "{$castedUpAttributeTableName}_id", $castedDownModelClassName::getTableName($castedDownModelClassName)); } } if (!$joinTablesAdapter->isTableInFromTables($attributeTableName)) { $tableAliasName = $joinTablesAdapter->addFromTableAndGetAliasName($attributeTableName, "{$attributeTableName}_id", $modelClassName::getTableName($modelClassName)); } } return $tableAliasName; }