Ejemplo n.º 1
0
 private function toObject($row)
 {
     $obj = new DDD();
     if (isset($row["ddd"])) {
         $obj->setDDD($row["ddd"]);
     }
     return $obj;
 }
 /**
  * DDD -> manyMany -> BBB -> hasOne -> GGG -> hasOne -> EEE (eeeMember and eeeMember2)
  * @depends testManyManyToHasOneToHasOne
  */
 public function testManyManyToHasOneToHasOneWithMultipleClauses()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ggg', 'relatedModelData' => array('attributeName' => 'eee', 'relatedModelData' => array('attributeName' => 'eeeMember', 'operatorType' => 'equals', 'value' => 'somevalue')))), 2 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ggg', 'relatedModelData' => array('attributeName' => 'eee', 'relatedModelData' => array('attributeName' => 'eeeMember2', 'operatorType' => 'equals', 'value' => 'somevalue')))));
     //Build the query 'where' and 'joins'. Confirm they are as expected
     $searchAttributeData['structure'] = '1 and 2';
     //Build the query 'where' and 'joins'. Confirm they are as expected
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('DDD');
     $where = ModelDataProviderUtil::makeWhere('DDD', $searchAttributeData, $joinTablesAdapter);
     $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue') and ";
     $compareWhere .= "({$quote}eee{$quote}.{$quote}eeemember2{$quote} = 'somevalue')";
     $this->assertEquals($compareWhere, $where);
     $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
     $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
     $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
     $this->assertEquals('bbb_ddd', $leftTables[0]['tableName']);
     $this->assertEquals('bbb', $leftTables[1]['tableName']);
     $this->assertEquals('ggg', $leftTables[2]['tableName']);
     $this->assertEquals('eee', $leftTables[3]['tableName']);
     //Stringing together some hasMany relations, so we need to select distinct.
     $this->assertTrue($joinTablesAdapter->getSelectDistinct());
     //Now test that the subsetSQL query produced is correct.
     $subsetSql = CCC::makeSubsetOrCountSqlQuery('ddd', $joinTablesAdapter, 1, 5, $where, null, false, $joinTablesAdapter->getSelectDistinct());
     $compareSubsetSql = "select distinct {$quote}ddd{$quote}.{$quote}id{$quote} id ";
     $compareSubsetSql .= "from {$quote}ddd{$quote} ";
     $compareSubsetSql .= "left join {$quote}bbb_ddd{$quote} on ";
     $compareSubsetSql .= "{$quote}bbb_ddd{$quote}.{$quote}ddd_id{$quote} = {$quote}ddd{$quote}.{$quote}id{$quote} ";
     $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
     $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}bbb_ddd{$quote}.{$quote}bbb_id{$quote} ";
     $compareSubsetSql .= "left join {$quote}ggg{$quote} on ";
     $compareSubsetSql .= "{$quote}ggg{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ggg_id{$quote} ";
     $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
     $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}ggg{$quote}.{$quote}eee_id{$quote} ";
     $compareSubsetSql .= "where " . $compareWhere . ' ';
     $compareSubsetSql .= 'limit 5 offset 1';
     $this->assertEquals($compareSubsetSql, $subsetSql);
     //Make sure the sql runs properly.
     $data = DDD::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
 }