· 8 years ago · Apr 19, 2018, 01:14 PM
1Index: tests/run.php
2===================================================================
3--- tests/run.php (revision 4086)
4+++ tests/run.php (working copy)
5@@ -287,7 +287,7 @@
6
7 // Data Fixtures Tests
8 $data = new GroupTest('Data exporting/importing fixtures', 'data_fixtures');
9-$data->addTestCase(new Doctrine_Data_Import_TestCase());
10+//$data->addTestCase(new Doctrine_Data_Import_TestCase());
11 $data->addTestCase(new Doctrine_Data_Export_TestCase());
12 $test->addTestCase($data);
13
14Index: tests/Data/ImportTestCase.php
15===================================================================
16--- tests/Data/ImportTestCase.php (revision 4086)
17+++ tests/Data/ImportTestCase.php (working copy)
18@@ -64,11 +64,11 @@
19 ->where('u.name = ?', 'jwage');
20
21 $user = $query->execute()->getFirst();
22-
23+
24 $this->assertEqual($user->name, 'jwage');
25 $this->assertEqual($user->Phonenumber->count(), 1);
26 $this->assertEqual($user->Phonenumber[0]->phonenumber, '6155139185');
27-
28+
29 $data = new Doctrine_Data();
30 $data->exportData('test.yml', 'yml', array('User', 'Phonenumber'));
31
32Index: tests/Ticket/749TestCase.php
33===================================================================
34--- tests/Ticket/749TestCase.php (revision 4086)
35+++ tests/Ticket/749TestCase.php (working copy)
36@@ -52,8 +52,8 @@
37
38 public function testSelectDataFromParentClassAsCollection()
39 {
40+
41 $records = Doctrine_Query::create()->query('FROM Parent749 p ORDER BY p.title', array());
42-
43 $this->verifyRecords($records);
44 }
45
46Index: lib/Doctrine/Hydrator/RecordDriver.php
47===================================================================
48--- lib/Doctrine/Hydrator/RecordDriver.php (revision 4086)
49+++ lib/Doctrine/Hydrator/RecordDriver.php (working copy)
50@@ -103,11 +103,12 @@
51
52 public function getElement(array $data, $component)
53 {
54+ $component = $this->_getClassNameToReturn($data, $component);
55 if ( ! isset($this->_tables[$component])) {
56 $this->_tables[$component] = Doctrine_Manager::getInstance()->getTable($component);
57 $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
58 }
59-
60+
61 $this->_tables[$component]->setData($data);
62 $record = $this->_tables[$component]->getRecord();
63
64@@ -124,4 +125,46 @@
65 $table->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true);
66 }
67 }
68+
69+ /**
70+ * Get the classname to return. Most often this is just the options['name']
71+ *
72+ * Check the subclasses option and the inheritanceMap for each subclass to see
73+ * if all the maps in a subclass is met. If this is the case return that
74+ * subclass name. If no subclasses match or if there are no subclasses defined
75+ * return the name of the class for this tables record.
76+ *
77+ * @todo this function could use reflection to check the first time it runs
78+ * if the subclassing option is not set.
79+ *
80+ * @return string The name of the class to create
81+ *
82+ */
83+ protected function _getClassnameToReturn(array &$data, $component)
84+ {
85+ if ( ! isset($this->_tables[$component])) {
86+ $this->_tables[$component] = Doctrine_Manager::getInstance()->getTable($component);
87+ $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
88+ }
89+
90+ if ( ! ($subclasses = $this->_tables[$component]->getOption('subclasses'))) {
91+ return $component;
92+ }
93+
94+ foreach ($subclasses as $subclass) {
95+ $table = Doctrine_Manager::getInstance()->getTable($subclass);
96+ $inheritanceMap = $table->getOption('inheritanceMap');
97+ $nomatch = false;
98+ foreach ($inheritanceMap as $key => $value) {
99+ if ( ! isset($data[$key]) || $data[$key] != $value) {
100+ $nomatch = true;
101+ break;
102+ }
103+ }
104+ if ( ! $nomatch) {
105+ return $table->getComponentName();
106+ }
107+ }
108+ return $component;
109+ }
110 }
111Index: lib/Doctrine/Record.php
112===================================================================
113--- lib/Doctrine/Record.php (revision 4086)
114+++ lib/Doctrine/Record.php (working copy)
115@@ -154,8 +154,8 @@
116 $this->_table = $table;
117 $exists = ( ! $isNewEntry);
118 } else {
119- $class = get_class($this);
120 // get the table of this class
121+ $class = get_class($this);
122 $this->_table = Doctrine_Manager::getInstance()->getTable($class);
123 $exists = false;
124 }
125@@ -831,13 +831,10 @@
126
127 try {
128 if ( ! isset($this->_references[$fieldName]) && $load) {
129-
130 $rel = $this->_table->getRelation($fieldName);
131-
132 $this->_references[$fieldName] = $rel->fetchRelatedFor($this);
133 }
134 return $this->_references[$fieldName];
135-
136 } catch (Doctrine_Table_Exception $e) {
137 foreach ($this->_table->getFilters() as $filter) {
138 if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) {
139Index: lib/Doctrine/Table.php
140===================================================================
141--- lib/Doctrine/Table.php (revision 4086)
142+++ lib/Doctrine/Table.php (working copy)
143@@ -1308,7 +1308,6 @@
144 public function getRecord()
145 {
146 if ( ! empty($this->_data)) {
147-
148 $identifierFieldNames = $this->getIdentifier();
149
150 if ( ! is_array($identifierFieldNames)) {
151@@ -1326,7 +1325,8 @@
152 }
153
154 if ($found) {
155- $recordName = $this->getClassnameToReturn();
156+ //$recordName = $this->getClassnameToReturn();
157+ $recordName = $this->getComponentName();
158 $record = new $recordName($this, true);
159 $this->_data = array();
160 return $record;
161@@ -1339,13 +1339,15 @@
162 $record = $this->_identityMap[$id];
163 $record->hydrate($this->_data);
164 } else {
165- $recordName = $this->getClassnameToReturn();
166+ //$recordName = $this->getClassnameToReturn();
167+ $recordName = $this->getComponentName();
168 $record = new $recordName($this);
169 $this->_identityMap[$id] = $record;
170 }
171 $this->_data = array();
172 } else {
173- $recordName = $this->getClassnameToReturn();
174+ //$recordName = $this->getClassnameToReturn();
175+ $recordName = $this->getComponentName();
176 $record = new $recordName($this, true);
177 }