diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php index add34bf22..a27965281 100644 --- a/lib/Doctrine/Configurable.php +++ b/lib/Doctrine/Configurable.php @@ -138,6 +138,7 @@ abstract class Doctrine_Configurable case Doctrine::ATTR_DEFAULT_SEQUENCE: case Doctrine::ATTR_EXPORT: case Doctrine::ATTR_DECIMAL_PLACES: + case Doctrine::ATTR_LOAD_REFERENCES: break; case Doctrine::ATTR_SEQCOL_NAME: diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 43dea4ed5..19bf1cc60 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -103,6 +103,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera Doctrine::ATTR_DQL_PARSER_CACHE => null, Doctrine::ATTR_DQL_CACHE => null, Doctrine::ATTR_SQL_CACHE => null, + Doctrine::ATTR_LOAD_REFERENCES => true, Doctrine::ATTR_LISTENER => new Doctrine_EventListener(), Doctrine::ATTR_LOCKMODE => 1, Doctrine::ATTR_VLD => false, diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 17a940b05..06085868c 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -145,10 +145,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite // get the table of this class $this->_table = Doctrine_Manager::getInstance() ->getTable(get_class($this)); - $exists = false; } - + // initialize the filter object $this->_filter = new Doctrine_Record_Filter($this); @@ -370,7 +369,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $this->_data[$k] = $v; } $this->_data = $this->_filter->cleanData($this->_data); - $this->prepareIdentifiers(); + $this->prepareIdentifiers(true); } /** * prepareIdentifiers @@ -1254,18 +1253,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @param string $name * @return void */ - final public function loadReference($name) + public function loadReference($name) { - - $fk = $this->_table->getRelation($name); - - if ($fk->isOneToOne()) { - $this->_references[$name] = $fk->fetchRelatedFor($this); - } else { - $coll = $fk->fetchRelatedFor($this); - - $this->_references[$name] = $coll; - } + $rel = $this->_table->getRelation($name); + $this->_references[$name] = $rel->fetchRelatedFor($this); } /** * ownsOne diff --git a/lib/Doctrine/Relation.php b/lib/Doctrine/Relation.php index ae9405d84..6670716f0 100644 --- a/lib/Doctrine/Relation.php +++ b/lib/Doctrine/Relation.php @@ -61,6 +61,7 @@ abstract class Doctrine_Relation 'local' => true, 'class' => true, 'type' => true, + 'table' => true, 'name' => false, 'refTable' => false, 'onDelete' => false, @@ -129,7 +130,7 @@ abstract class Doctrine_Relation $this->definition = $def; } - /** + /** * toArray * * @return array diff --git a/lib/Doctrine/Relation/Association.php b/lib/Doctrine/Relation/Association.php index c48420d96..4cc1760c4 100644 --- a/lib/Doctrine/Relation/Association.php +++ b/lib/Doctrine/Relation/Association.php @@ -88,7 +88,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation public function fetchRelatedFor(Doctrine_Record $record) { $id = $record->getIncremented(); - if (empty($id)) { + if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { $coll = new Doctrine_Collection($this->getTable()); } else { $coll = Doctrine_Query::create()->parseQuery($this->getRelationDql(1))->execute(array($id)); diff --git a/lib/Doctrine/Relation/ForeignKey.php b/lib/Doctrine/Relation/ForeignKey.php index 3433732f7..bfdde5aba 100644 --- a/lib/Doctrine/Relation/ForeignKey.php +++ b/lib/Doctrine/Relation/ForeignKey.php @@ -51,7 +51,9 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation } } if ($this->isOneToOne()) { - if ( ! $record->exists() || empty($id)) { + if ( ! $record->exists() || empty($id) || + ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { + $related = $this->getTable()->create(); } else { $dql = 'FROM ' . $this->getTable()->getComponentName() @@ -65,7 +67,9 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation } else { - if ( ! $record->exists() || empty($id)) { + if ( ! $record->exists() || empty($id) || + ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { + $related = new Doctrine_Collection($this->getTable()); } else { $query = $this->getRelationDql(1); diff --git a/lib/Doctrine/Relation/LocalKey.php b/lib/Doctrine/Relation/LocalKey.php index db86ed6bc..b3117568e 100644 --- a/lib/Doctrine/Relation/LocalKey.php +++ b/lib/Doctrine/Relation/LocalKey.php @@ -45,7 +45,7 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation { $id = $record->get($this->definition['local']); - if (empty($id)) { + if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { $related = $this->getTable()->create(); } else { $related = $this->getTable()->find($id);