Changeset 2299

Show
Ignore:
Timestamp:
03/13/2008 01:53:08 AM (8 months ago)
Author:
Shadowhand
Message:

Changes to ORM:

  • Added Database::from() detection
  • Optimized cal() for has/add/remove
  • Other small optimizations
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/ORM.php

    r2280 r2299  
    3232        protected $select = FALSE; 
    3333        protected $where = FALSE; 
     34        protected $from = FALSE; 
    3435 
    3536        // Currently loaded object 
     
    233234                if (preg_match('/^(has|add|remove)_(.+)/', $method, $matches)) 
    234235                { 
     236                        if (empty($this->object->id)) 
     237                        { 
     238                                // many<>many relationships only work when the object has been saved 
     239                                return FALSE; 
     240                        } 
     241 
    235242                        // Make a has/add/remove call 
    236243                        return $this->call_has_add_remove($method, $args, $matches); 
     
    247254                                $this->select = TRUE; 
    248255                        } 
    249                         elseif (preg_match('/where|like|regex/', $method)) 
     256                        elseif (preg_match('/where|like|in|regex/', $method)) 
    250257                        { 
    251258                                $this->where = TRUE; 
     259                        } 
     260                        elseif ($method === 'from') 
     261                        { 
     262                                $this->from = TRUE; 
    252263                        } 
    253264 
     
    703714                // Reset object status 
    704715                $this->changed = array(); 
    705                 $this->select  = FALSE; 
    706                 $this->where   = FALSE; 
     716                $this->select = $this->where = $this->from = FALSE; 
    707717 
    708718                return $this; 
     
    738748                $this->select or self::$db->select($this->table.'.*'); 
    739749 
     750                // Make sure there is a table to select from 
     751                $this->from or self::$db->from($this->table); 
     752 
    740753                // Fetch the query result 
    741                 $result = self::$db->get($this->table)->result(TRUE); 
     754                $result = self::$db->get()->result(TRUE); 
    742755 
    743756                if ($array === TRUE) 
     
    771784                // Clear the changed keys, a new object has been loaded 
    772785                $this->changed = array(); 
    773                 $this->select = FALSE; 
    774                 $this->where = FALSE; 
     786                $this->select = $this->where = $this->from = FALSE; 
    775787 
    776788                // Return this object