|
16 | 16 | * @method dbObject ObjectBuilder() |
17 | 17 | * @method mixed byId (string $id, mixed $fields) |
18 | 18 | * @method mixed get (mixed $limit, mixed $fields) |
19 | | - * @method mixed getOne (mixed $fields) |
| 19 | + * @method mixed getOne (mixed $fields)processAllWith |
20 | 20 | * @method mixed paginate (int $page, array $fields) |
21 | 21 | * @method dbObject query ($query, $numRows) |
22 | 22 | * @method dbObject rawQuery ($query, $bindParams, $sanitize) |
@@ -521,18 +521,23 @@ private function processAllWith (&$data, $shouldReset = true) { |
521 | 521 | if ($relationType == 'hasone') { |
522 | 522 | $obj = new $modelName; |
523 | 523 | $table = $obj->dbTable; |
524 | | - |
| 524 | + $primaryKey = $obj->primaryKey; |
| 525 | + |
525 | 526 | if (!isset ($data[$table])) { |
526 | 527 | $data[$name] = $this->$name; |
527 | 528 | continue; |
528 | | - } |
529 | | - if ($this->returnType == 'Object') { |
530 | | - $item = new $modelName ($data[$table]); |
531 | | - $item->returnType = $this->returnType; |
532 | | - $item->isNew = false; |
533 | | - $data[$name] = $item; |
| 529 | + } |
| 530 | + if ($data[$table][$primaryKey] === null) { |
| 531 | + $data[$name] = null; |
534 | 532 | } else { |
535 | | - $data[$name] = $data[$table]; |
| 533 | + if ($this->returnType == 'Object') { |
| 534 | + $item = new $modelName ($data[$table]); |
| 535 | + $item->returnType = $this->returnType; |
| 536 | + $item->isNew = false |
| 537 | + $data[$name] = $item; |
| 538 | + } else { |
| 539 | + $data[$name] = $data[$table]; |
| 540 | + } |
536 | 541 | } |
537 | 542 | unset ($data[$table]); |
538 | 543 | } |
|
0 commit comments