Working with objects - Component overview - Record - Getting record state.php 1.44 KB
Newer Older
hansbrix's avatar
hansbrix committed
1 2 3 4
Every Doctrine_Record has a state. First of all record can be transient or persistent.
Every record that is retrieved from database is persistent and every newly created record is transient.
If a Doctrine_Record is retrieved from database but the only loaded property is its primary key, then this record
has a state called proxy.
5

hansbrix's avatar
hansbrix committed
6 7 8 9
Every transient and persistent Doctrine_Record is either clean or dirty. Doctrine_Record is clean when none of its properties are changed and
dirty when atleast one of its properties has changed. 

<code type="php">
zYne's avatar
zYne committed
10
$state = $record->state();
hansbrix's avatar
hansbrix committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

switch($state):
    case Doctrine_Record::STATE_PROXY:
        // record is in proxy state, 
        // meaning its persistent but not all of its properties are
        // loaded from the database
    break;
    case Doctrine_Record::STATE_TCLEAN:
        // record is transient clean,
        // meaning its transient and 
        // none of its properties are changed
    break;
    case Doctrine_Record::STATE_TDIRTY:
        // record is transient dirty,
        // meaning its transient and 
        // some of its properties are changed
    break;
    case Doctrine_Record::STATE_DIRTY:
        // record is dirty, 
        // meaning its persistent and 
        // some of its properties are changed
    break;
    case Doctrine_Record::STATE_CLEAN:
        // record is clean,
        // meaning its persistent and 
        // none of its properties are changed
    break;
endswitch;
</code>