Commits

Jason Green committed 50b67a1

More work to eliminate unneeded beans

  • Participants
  • Parent commits 665abe0
  • Branches classbeanrefactor

Comments (0)

Files changed (6)

File app/protected/core/adapters/RedBeanModelAttributeToDataProviderAdapter.php

         }
 
         /**
+         * If the relation model class can have a bean.
+         */
+        public function canRelationHaveTable()
+        {
+            $modelClassName = $this->getRelationModelClassName();
+            return $modelClassName::getCanHaveBean();
+        }
+
+        /**
          * If the attribute is a relation, returns the relation's table name.
          */
         public function getRelationTableName()

File app/protected/core/utils/ModelDataProviderUtil.php

                 $onTableJoinIdName  = $modelAttributeToDataProviderAdapter->getColumnName();
                 $tableJoinIdName    = 'id';
             }
-            $relationTableAliasName          = $joinTablesAdapter->addLeftTableAndGetAliasName(
-                                               $modelAttributeToDataProviderAdapter->getRelationTableName(),
-                                               $onTableJoinIdName,
-                                               $onTableAliasName,
-                                               $tableJoinIdName);
+            if(!$modelAttributeToDataProviderAdapter->canRelationHaveTable())
+            {
+                $relationTableAliasName          = $onTableAliasName;
+            }
+            else
+            {
+                $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.
                 elseif (get_parent_class($modelAttributeToDataProviderAdapter->getRelationModelClassName()) ==
                         $modelAttributeToDataProviderAdapter->getRelatedAttributeModelClassName())
                 {
-                    $onTableJoinIdName = "{$relationAttributeTableName}_id";
+                    $onTableJoinIdName = $modelAttributeToDataProviderAdapter->getColumnName();
                 }
                 else
                 {

File app/protected/modules/zurmo/models/OwnedMultipleValuesCustomField.php

          */
         public static function getCanHaveBean()
         {
-            if(get_called_class() == 'OwnedCustomField')
+            if(get_called_class() == 'OwnedMultipleValuesCustomField')
             {
                 return self::$canHaveBean;
             }

File app/protected/modules/zurmo/tests/unit/OwnedMultipleValuesCustomFieldDataProviderTest.php

                 $this->assertEquals($compareWhere, $where);
                 //Now test that the joinTablesAdapter has correct information.
                 $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
-                $this->assertEquals(2, $joinTablesAdapter->getLeftTableJoinCount());
+                $this->assertEquals(1, $joinTablesAdapter->getLeftTableJoinCount());
                 $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
-                $this->assertEquals('ownedmultiplevaluescustomfield', $leftTables[0]['tableName']);
-                $this->assertEquals('multiplevaluescustomfield',      $leftTables[1]['tableName']);
+                $this->assertEquals('multiplevaluescustomfield',      $leftTables[0]['tableName']);
 
                 //Now test that the subsetSQL query produced is correct.
                 $subsetSql         = TestOwnedCustomFieldsModel::
                                      makeSubsetOrCountSqlQuery('testownedcustomfieldsmodel', $joinTablesAdapter, 1, 5, $where, null);
                 $compareSubsetSql  = "select {$quote}testownedcustomfieldsmodel{$quote}.{$quote}id{$quote} id ";
                 $compareSubsetSql .= "from {$quote}testownedcustomfieldsmodel{$quote} ";
-                $compareSubsetSql .= "left join {$quote}ownedmultiplevaluescustomfield{$quote} on ";
-                $compareSubsetSql .= "{$quote}ownedmultiplevaluescustomfield{$quote}.{$quote}id{$quote} = ";
-                $compareSubsetSql .= "{$quote}testownedcustomfieldsmodel{$quote}.{$quote}multipleindustries_ownedmultiplevaluescustomfield_id{$quote} ";
                 $compareSubsetSql .= "left join {$quote}multiplevaluescustomfield{$quote} on ";
                 $compareSubsetSql .= "{$quote}multiplevaluescustomfield{$quote}.{$quote}id{$quote} = ";
-                $compareSubsetSql .= "{$quote}ownedmultiplevaluescustomfield{$quote}.{$quote}multiplevaluescustomfield_id{$quote} ";
+                $compareSubsetSql .= "{$quote}testownedcustomfieldsmodel{$quote}.{$quote}multipleindustries_multiplevaluescustomfield_id{$quote} ";
                 $compareSubsetSql .= "where " . $compareWhere . ' ';
                 $compareSubsetSql .= 'limit 5 offset 1';
                 $this->assertEquals($compareSubsetSql, $subsetSql);
                 $this->assertEquals($compareWhere, $where);
                 //Now test that the joinTablesAdapter has correct information.
                 $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
-                $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
+                $this->assertEquals(2, $joinTablesAdapter->getLeftTableJoinCount());
                 $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
-                $this->assertEquals('ownedmultiplevaluescustomfield', $leftTables[0]['tableName']);
+                $this->assertEquals('multiplevaluescustomfield',      $leftTables[0]['tableName']);
                 $this->assertEquals('multiplevaluescustomfield',      $leftTables[1]['tableName']);
-                $this->assertEquals('ownedmultiplevaluescustomfield', $leftTables[2]['tableName']);
-                $this->assertEquals('multiplevaluescustomfield',      $leftTables[3]['tableName']);
 
                 //Now test that the subsetSQL query produced is correct.
                 $subsetSql         = TestOwnedCustomFieldsModel::
                                      makeSubsetOrCountSqlQuery('testcustomfieldsmodel', $joinTablesAdapter, 1, 5, $where, null);
                 $compareSubsetSql  = "select {$quote}testcustomfieldsmodel{$quote}.{$quote}id{$quote} id ";
                 $compareSubsetSql .= "from {$quote}testcustomfieldsmodel{$quote} ";
-                $compareSubsetSql .= "left join {$quote}ownedmultiplevaluescustomfield{$quote} on ";
-                $compareSubsetSql .= "{$quote}ownedmultiplevaluescustomfield{$quote}.{$quote}id{$quote} = ";
-                $compareSubsetSql .= "{$quote}testownedcustomfieldsmodel{$quote}.{$quote}multipleindustries_ownedmultiplevaluescustomfield_id{$quote} ";
                 $compareSubsetSql .= "left join {$quote}multiplevaluescustomfield{$quote} on ";
                 $compareSubsetSql .= "{$quote}multiplevaluescustomfield{$quote}.{$quote}id{$quote} = ";
-                $compareSubsetSql .= "{$quote}ownedmultiplevaluescustomfield{$quote}.{$quote}multiplevaluescustomfield_id{$quote} ";
-                $compareSubsetSql .= "left join {$quote}ownedmultiplevaluescustomfield{$quote} ownedmultiplevaluescustomfield1 on ";
-                $compareSubsetSql .= "{$quote}ownedmultiplevaluescustomfield1{$quote}.{$quote}id{$quote} = ";
-                $compareSubsetSql .= "{$quote}testownedcustomfieldsmodel{$quote}.{$quote}multiplesomethings_ownedmultiplevaluescustomfield_id{$quote} ";
+                $compareSubsetSql .= "{$quote}testownedcustomfieldsmodel{$quote}.{$quote}multipleindustries_multiplevaluescustomfield_id{$quote} ";
                 $compareSubsetSql .= "left join {$quote}multiplevaluescustomfield{$quote} multiplevaluescustomfield1 on ";
                 $compareSubsetSql .= "{$quote}multiplevaluescustomfield1{$quote}.{$quote}id{$quote} = ";
-                $compareSubsetSql .= "{$quote}ownedmultiplevaluescustomfield1{$quote}.{$quote}multiplevaluescustomfield_id{$quote} ";
+                $compareSubsetSql .= "{$quote}testownedcustomfieldsmodel{$quote}.{$quote}multiplesomethings_multiplevaluescustomfield_id{$quote} ";
                 $compareSubsetSql .= "where " . $compareWhere . ' ';
                 $compareSubsetSql .= 'limit 5 offset 1';
                 $this->assertEquals($compareSubsetSql, $subsetSql);

File app/protected/modules/zurmo/tests/unit/SearchOwnedCustomFieldRecursiveDataTest.php

             $compareWhere      = "({$quote}customfield{$quote}.{$quote}value{$quote} IN('something'))";
             $this->assertEquals($compareWhere, $where);
             $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
-            $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
+            $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount());
             $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
             $this->assertEquals('contact_opportunity',     $leftTables[0]['tableName']);
             $this->assertEquals('opportunity',             $leftTables[1]['tableName']);
-            $this->assertEquals('ownedcustomfield',        $leftTables[2]['tableName']);
-            $this->assertEquals('customfield',             $leftTables[3]['tableName']);
+            $this->assertEquals('customfield',             $leftTables[2]['tableName']);
             $this->assertTrue($joinTablesAdapter->getSelectDistinct());
 
             //Now test that the subsetSQL query produced is correct.
             $compareSubsetSql .= "{$quote}contact_opportunity{$quote}.{$quote}contact_id{$quote} = {$quote}contact{$quote}.{$quote}id{$quote} ";
             $compareSubsetSql .= "left join {$quote}opportunity{$quote} on ";
             $compareSubsetSql .= "{$quote}opportunity{$quote}.{$quote}id{$quote} = {$quote}contact_opportunity{$quote}.{$quote}opportunity_id{$quote} ";
-            $compareSubsetSql .= "left join {$quote}ownedcustomfield{$quote} on ";
-            $compareSubsetSql .= "{$quote}ownedcustomfield{$quote}.{$quote}id{$quote} = {$quote}opportunity{$quote}.{$quote}stage_ownedcustomfield_id{$quote} ";
             $compareSubsetSql .= "left join {$quote}customfield{$quote} on ";
-            $compareSubsetSql .= "{$quote}customfield{$quote}.{$quote}id{$quote} = {$quote}ownedcustomfield{$quote}.{$quote}customfield_id{$quote} ";
+            $compareSubsetSql .= "{$quote}customfield{$quote}.{$quote}id{$quote} = {$quote}opportunity{$quote}.{$quote}stage_customfield_id{$quote} ";
             $compareSubsetSql .= "where " . $compareWhere . ' ';
             $compareSubsetSql .= 'limit 5 offset 1';
             $this->assertEquals($compareSubsetSql, $subsetSql);

File app/protected/modules/zurmo/tests/unit/ZurmoModelsDataProviderDocumentationTest.php

 
             //Is the join information correct?
             $leftTablesAndAliases = $joinTablesAdapter->getLeftTablesAndAliases();
-            $this->assertEquals('ownedcustomfield',             $leftTablesAndAliases[0]['tableName']);
-            $this->assertEquals('ownedcustomfield',             $leftTablesAndAliases[0]['tableAliasName']);
+            $this->assertEquals('customfield',                  $leftTablesAndAliases[0]['tableName']);
+            $this->assertEquals('customfield',                  $leftTablesAndAliases[0]['tableAliasName']);
             $this->assertEquals('id',                           $leftTablesAndAliases[0]['tableJoinIdName']);
             $this->assertEquals('account',                      $leftTablesAndAliases[0]['onTableAliasName']);
-            $this->assertEquals('industry_ownedcustomfield_id', $leftTablesAndAliases[0]['onTableJoinIdName']);
-            $this->assertEquals('customfield',                  $leftTablesAndAliases[1]['tableName']);
-            $this->assertEquals('customfield',                  $leftTablesAndAliases[1]['tableAliasName']);
-            $this->assertEquals('id',                           $leftTablesAndAliases[1]['tableJoinIdName']);
-            $this->assertEquals('ownedcustomfield',             $leftTablesAndAliases[1]['onTableAliasName']);
-            $this->assertEquals('customfield_id',               $leftTablesAndAliases[1]['onTableJoinIdName']); //this is going to fail.... need to fix.
+            $this->assertEquals('industry_customfield_id',      $leftTablesAndAliases[0]['onTableJoinIdName']);
 
             //Is the entire query correct? It should be.
             $subsetSql = Account::makeSubsetOrCountSqlQuery('account', $joinTablesAdapter, 1, 5, $where);
             $compareSubsetSql  = "select {$quote}account{$quote}.{$quote}id{$quote} id ";
             $compareSubsetSql .= "from {$quote}account{$quote} ";
-            $compareSubsetSql .= "left join {$quote}ownedcustomfield{$quote} on ";
-            $compareSubsetSql .= "{$quote}ownedcustomfield$quote.{$quote}id{$quote} = {$quote}account$quote.{$quote}industry_ownedcustomfield_id{$quote} ";
             $compareSubsetSql .= "left join {$quote}customfield{$quote} on ";
-            $compareSubsetSql .= "{$quote}customfield$quote.{$quote}id{$quote} = {$quote}ownedcustomfield$quote.{$quote}customfield_id{$quote}";
+            $compareSubsetSql .= "{$quote}customfield$quote.{$quote}id{$quote} = {$quote}account$quote.{$quote}industry_customfield_id{$quote}";
             $compareSubsetSql .= " where ({$quote}customfield{$quote}.{$quote}value{$quote} = 'Automotive') ";
             $compareSubsetSql .= "limit 5 offset 1";
             $this->assertEquals($compareSubsetSql, $subsetSql);