Changeset 1365

Show
Ignore:
Timestamp:
08/07/09 05:15:55 (1 year ago)
Author:
arnoschn
Message:

- Fixing #265 serialize problem on associated models

  • also fixing serialize behaviour on returns=>array/simulated

- Allowing setting of context in ActiveRecord->t($string,$params,$context)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/AkActiveRecord.php

    r1361 r1365  
    842842        $sql = 'DELETE FROM '.$this->getTableName().' WHERE '.$this->getPrimaryKey().' = '.$this->castAttributeForDatabase($this->getPrimaryKey(), $this->getId()); 
    843843        if ($this->_db->delete($sql,$this->getModelName().' Destroy') !== 1){ 
    844             return $this->transactionFail(); 
     844            return $this->transactionFail(); 
    845845        } 
    846846 
     
    10901090 
    10911091    } 
    1092  
    10931092    function quotedId($id = false) 
    10941093    { 
    10951094        return $this->castAttributeForDatabase($this->getPrimaryKey(), $id ? $id : $this->getId()); 
    10961095    } 
    1097  
    10981096    function _extractOptionsFromArgs(&$args) 
    10991097    { 
     
    12301228                $objects[] =& $this->instantiate($this->getOnlyAvailableAttributes($record), false); 
    12311229            } else if ($returns == 'simulated') { 
    1232                 $objects[] = $this->getOnlyAvailableAttributes($record); 
     1230                $objects[] = $this->_castAttributesFromDatabase($this->getOnlyAvailableAttributes($record),$this); 
    12331231            } else if ($returns == 'array') { 
    12341232 
    1235                 $objects[] = $this->getOnlyAvailableAttributes($record); 
     1233                $objects[] = $this->_castAttributesFromDatabase($this->getOnlyAvailableAttributes($record),$this); 
    12361234            } 
    12371235        } 
     
    30333031    */ 
    30343032 
    3035     function t($string, $array = null
    3036     { 
    3037         return Ak::t($string, $array, AkInflector::underscore($this->getModelName())); 
     3033    function t($string, $array = null,$model=null
     3034    { 
     3035        return Ak::t($string, $array, empty($model)?AkInflector::underscore($this->getModelName()):$model); 
    30383036    } 
    30393037 
     
    34113409        if(empty($imported_cache[$column_name])){ 
    34123410            $class_name = isset($this->serialize[$column_name])  ? 
    3413             (is_string($this->serialize[$column_name]) ? $this->serialize[$column_name] : $column_name) : $column_name; 
    3414             Ak::import($class_name); 
     3411            (is_string($this->serialize[$column_name]) ? $this->serialize[$column_name] : $column_name) : false; 
     3412            if($class_name) { 
     3413                Ak::import($class_name); 
     3414            } 
    34153415            $imported_cache[$column_name] = true; 
    34163416        } 
  • trunk/lib/AkActiveRecord/AkAssociatedActiveRecord.php

    r1351 r1365  
    258258        $load_acts = isset($options['load_acts'])?$options['load_acts']:true; 
    259259 
    260         $config = array('__owner'=>array('class'=>$this->getType(),'pk'=>$this->getPrimaryKey())); 
     260        $config = array('__owner'=>array('class'=>$this->getType(),'pk'=>$this->getPrimaryKey(),'instance'=>$this)); 
    261261 
    262262        $returns = isset($options['returns'])?$options['returns']:'default'; 
     
    313313                } 
    314314            } 
    315             $config['__owner'][$handler_name] = array('class'=>$class,'association_id'=>$association_id,'pk'=>$pk_name); 
     315            $config['__owner'][$handler_name] = array('class'=>$class,'association_id'=>$association_id,'pk'=>$pk_name,'instance'=>$instance); 
    316316             
    317317            if(isset($association_options['conditions']) && is_array($association_options['conditions'])) { 
     
    493493                $table_name = $instance->getTableName(); 
    494494            } 
    495             $config[$handler_name][$sub_handler_name] = array('association_id'=>$sub_association_id,'class'=>$class_name,'pk'=>$pk); 
     495            $config[$handler_name][$sub_handler_name] = array('association_id'=>$sub_association_id,'class'=>$class_name,'pk'=>$pk, 'instance'=>$instance); 
    496496            $sub_associated_options = $sub_association_object->$sub_handler_name->getAssociatedFinderSqlOptionsForInclusionChain($prefix.'['.$handler_name.']'.($parent_is_plural?'[@'.$pk.']':''),'__owner__'.$parent_association_id, 
    497497            $sub_options, $pluralize); 
     
    769769                $association = $key; 
    770770 
    771                 if (isset($config[$key]) && $returns == 'array') { 
     771                if (isset($config[$key])) { 
    772772                    $config = $config[$key]; 
    773                     $association = $config['association_id']; 
     773                    if($returns=='array') { 
     774                        $association = $config['association_id']; 
     775                    } 
    774776                    //$this->log('using association:'.$association); 
    775777                } 
     
    780782 
    781783            } 
     784            $value=$this->_castAttributeFromDatabase($association,$value,$config['instance']); 
    782785            $last = $value; 
    783786        } 
     
    880883                } 
    881884            }*/ 
    882             $available = $this->_castAttributesFromDatabase($available,$instance); 
     885            //$available = $this->_castAttributesFromDatabase($available,$instance); 
    883886            $obj=&$parent->$assoc_name->build($available,false); 
    884887