Ejemplo n.º 1
0
 /**
  * Receive a belongsTo relation.
  *
  * @param string $key The name of the belongsTo relation.
  *
  * @return Phprojekt_ActiveRecord An instance of Phprojekt_ActiveRecord.
  */
 protected function _belongsTo($key)
 {
     if (!array_key_exists($key, $this->belongsTo)) {
         throw new Phprojekt_ActiveRecord_Exception("BelongsTo {$key} does not exist");
     }
     if (!array_key_exists($key, $this->_data)) {
         $className = $this->_getClassNameForRelationship($key, $this->belongsTo);
         $instance = new $className(array('db' => $this->getAdapter()));
         $foreignKeyName = $this->_translateKeyFormat($className);
         $foreignKeyName = Phprojekt_ModuleInstance::convertVarFromSql($foreignKeyName);
         if (array_key_exists($foreignKeyName, $this->_data)) {
             $other = $instance->find($this->_data[$foreignKeyName]);
             if (!empty($other)) {
                 $this->_data[$key] = $instance->find($this->_data[$foreignKeyName]);
             } else {
                 throw new Phprojekt_ActiveRecord_Exception("{$key} with id {$this->_data[$foreignKeyname]} not found");
             }
         } else {
             $this->_data[$key] = null;
         }
     }
     return $this->_data[$key];
 }
Ejemplo n.º 2
0
 /**
  * Test sql conversion, calls are static here to avoid Db adapter confusion
  */
 public function testVarFromSql()
 {
     $this->assertEquals('lowcaseUnderscored', Phprojekt_ModuleInstance::convertVarFromSql('lowcase_underscored'));
     $this->assertEquals('LowcaseUnderscored', Phprojekt_ModuleInstance::convertVarFromSql('Lowcase_underscored'));
     $this->assertEquals('lowcasenoscore', Phprojekt_ModuleInstance::convertVarFromSql('lowcasenoscore'));
     $this->assertEquals('Lowcasenoscore', Phprojekt_ModuleInstance::convertVarFromSql('Lowcasenoscore'));
     $this->assertEquals('123textText', Phprojekt_ModuleInstance::convertVarFromSql('123text_text'));
     $this->assertEquals('abcäöüxyz', Phprojekt_ModuleInstance::convertVarFromSql('abcäöüxyz'));
     $this->assertEquals('Äöü123abc', Phprojekt_ModuleInstance::convertVarFromSql('Äöü123abc'));
 }