Commit ecbecaa6 authored by zYne's avatar zYne

new attribute Doctrine::ATTR_LOAD_REFERENCES

parent b8559e37
......@@ -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:
......
......@@ -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,
......
......@@ -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
......
......@@ -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
......
......@@ -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));
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment