Changeset 4778

Show
Ignore:
Timestamp:
08/19/08 01:27:22 (11 months ago)
Author:
guilhermeblanco
Message:

fixed #1280. Fixed Export that never deals with default=null in all DBMS. Also fixed $entity->Relation = null; situation that cleans the reference.
Now we have unset and unlink that deletes related object and = null that only defines the default value when save() is called.

Location:
branches/1.0
Files:
1 added
8 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/DataDict/Mysql.php

    r4768 r4778  
    458458                $field['default'] = empty($field['notnull']) ? null : 0; 
    459459            } 
    460             if (is_null($field['default'])) { 
    461                 $default = ' DEFAULT NULL'; 
    462             } else { 
    463                 $default = ' DEFAULT '.$this->conn->quote($field['default']); 
    464             } 
     460 
     461            $default = ' DEFAULT ' . (is_null($field['default']) 
     462                ? 'NULL' 
     463                : $this->conn->quote($field['default'])); 
    465464        } 
    466465        /** 
  • branches/1.0/lib/Doctrine/DataDict/Pgsql.php

    r4768 r4778  
    614614                $field['default'] = empty($field['notnull']) ? null : 0; 
    615615            } 
    616             $default = ' DEFAULT '.$this->conn->quote($field['default'], $field['type']); 
     616 
     617            $default = ' DEFAULT ' . (is_null($field['default']) 
     618                ? 'NULL' 
     619                : $this->conn->quote($field['default'], $field['type'])); 
    617620        } 
    618621        /** 
  • branches/1.0/lib/Doctrine/DataDict/Sqlite.php

    r4768 r4778  
    296296                $field['default'] = empty($field['notnull']) ? null : 0; 
    297297            } 
    298             $default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']); 
     298 
     299            $default = ' DEFAULT ' . (is_null($field['default']) 
     300                ? 'NULL' 
     301                : $this->conn->quote($field['default'], $field['type'])); 
    299302        }/** 
    300303        elseif (empty($field['notnull'])) { 
  • branches/1.0/lib/Doctrine/Export.php

    r4736 r4778  
    752752    { 
    753753        $default = ''; 
    754         if (isset($field['default'])) { 
     754 
     755        if (array_key_exists('default', $field)) { 
    755756            if ($field['default'] === '') { 
    756757                $field['default'] = empty($field['notnull']) 
     
    766767                $field['default'] = $this->conn->convertBooleans($field['default']); 
    767768            } 
    768             $default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']); 
    769         } 
     769            $default = ' DEFAULT ' . (is_null($field['default']) 
     770                ? 'NULL' 
     771                : $this->conn->quote($field['default'], $field['type'])); 
     772        } 
     773 
    770774        return $default; 
    771775    } 
  • branches/1.0/lib/Doctrine/Export/Mysql.php

    r4731 r4778  
    605605            } 
    606606             
    607             $default = ' DEFAULT ' . $this->conn->quote($field['default'], $fieldType); 
     607            $default = ' DEFAULT ' . (is_null($field['default']) 
     608                ? 'NULL'  
     609                : $this->conn->quote($field['default'], $fieldType)); 
    608610            //$default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']); 
    609611        } 
     612         
    610613        return $default; 
    611614    } 
  • branches/1.0/lib/Doctrine/Record.php

    r4772 r4778  
    10351035                    throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references."); 
    10361036                } 
     1037 
    10371038                if (isset($this->_references[$name])) { 
    10381039                    $this->_references[$name]->setData($value->getData()); 
     1040 
    10391041                    return $this; 
    10401042                } 
    10411043            } else { 
     1044                $localFieldName = $this->_table->getFieldName($rel->getLocal()); 
     1045 
    10421046                if ($value !== self::$_null) { 
    10431047                    $relatedTable = $value->getTable(); 
    10441048                    $foreignFieldName = $relatedTable->getFieldName($rel->getForeign()); 
    1045                     $localFieldName = $this->_table->getFieldName($rel->getLocal()); 
    1046  
    1047                     // one-to-one relation found 
    1048                     if ( ! ($value instanceof Doctrine_Record)) { 
    1049                         throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Record or Doctrine_Null when setting one-to-one references."); 
     1049                } 
     1050 
     1051                // one-to-one relation found 
     1052                if ( ! ($value instanceof Doctrine_Record) && ! ($value instanceof Doctrine_Null)) { 
     1053                    throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Record or Doctrine_Null when setting one-to-one references."); 
     1054                } 
     1055 
     1056                if ($rel instanceof Doctrine_Relation_LocalKey) { 
     1057                    if ($value !== self::$_null &&  ! empty($foreignFieldName) && $foreignFieldName != $value->getTable()->getIdentifier()) { 
     1058                        $this->set($localFieldName, $value->rawGet($foreignFieldName), false); 
     1059                    } else { 
     1060                        // FIX: Ticket #1280 fits in this situation 
     1061                        $this->set($localFieldName, $value, false); 
    10501062                    } 
    1051                     if ($rel instanceof Doctrine_Relation_LocalKey) { 
    1052                         if ( ! empty($foreignFieldName) && $foreignFieldName != $value->getTable()->getIdentifier()) { 
    1053                             $this->set($localFieldName, $value->rawGet($foreignFieldName), false); 
    1054                         } else { 
    1055                             $this->set($localFieldName, $value, false); 
    1056                         } 
    1057                     } else { 
    1058                         $value->set($foreignFieldName, $this, false); 
    1059                     } 
     1063                } elseif ($value !== self::$_null) { 
     1064                    // We should only be able to reach $foreignFieldName if we have a Doctrine_Record on hands 
     1065                    $value->set($foreignFieldName, $this, false); 
    10601066                } 
    10611067            } 
    1062  
    10631068        } else if ($rel instanceof Doctrine_Relation_Association) { 
    10641069            // join table relation found 
  • branches/1.0/lib/Doctrine/Record/Abstract.php

    r4681 r4778  
    4040    public function setTableDefinition() 
    4141    { 
    42          
     42 
    4343    } 
    4444    public function setUp() 
  • branches/1.0/tests/run.php

    r4777 r4778  
    115115$tickets->addTestCase(new Doctrine_Ticket_1257_TestCase()); 
    116116$tickets->addTestCase(new Doctrine_Ticket_1277_TestCase()); 
     117$tickets->addTestCase(new Doctrine_Ticket_1280_TestCase()); 
    117118$tickets->addTestCase(new Doctrine_Ticket_1289_TestCase()); 
    118119$tickets->addTestCase(new Doctrine_Ticket_1296_TestCase());