Skip to content

Commit df1143b

Browse files
committed
Merge branch 'master' of github.com:fzhan/codeigniter-base-model into fzhan-master
2 parents 6dc6d52 + 775945c commit df1143b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

core/MY_Model.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ public function with($relationship)
462462

463463
public function relate($row)
464464
{
465+
if (empty($row))
466+
return $row;
467+
465468
foreach ($this->belongs_to as $key => $value)
466469
{
467470
if (is_string($value))
@@ -477,14 +480,14 @@ public function relate($row)
477480

478481
if (in_array($relationship, $this->_with))
479482
{
480-
$this->load->model($options['model']);
483+
$this->load->model($options['model'],$relationship);
481484
if (is_object($row))
482485
{
483-
$row->{$relationship} = $this->{$options['model']}->get($row->{$options['primary_key']});
486+
$row->{$relationship} = $this->{$relationship}->get($row->{$options['primary_key']});
484487
}
485488
else
486489
{
487-
$row[$relationship] = $this->{$options['model']}->get($row[$options['primary_key']]);
490+
$row[$relationship] = $this->{$relationship}->get($row[$options['primary_key']]);
488491
}
489492
}
490493
}
@@ -504,14 +507,14 @@ public function relate($row)
504507

505508
if (in_array($relationship, $this->_with))
506509
{
507-
$this->load->model($options['model']);
510+
$this->load->model($options['model'],$relationship);
508511
if (is_object($row))
509512
{
510-
$row->{$relationship} = $this->{$options['model']}->get_many_by($options['primary_key'], $row->{$this->primary_key});
513+
$row->{$relationship} = $this->{$relationship}->get_many_by($options['primary_key'], $row->{$this->primary_key});
511514
}
512515
else
513516
{
514-
$row[$relationship] = $this->{$options['model']}->get_many_by($options['primary_key'], $row[$this->primary_key]);
517+
$row[$relationship] = $this->{$relationship}->get_many_by($options['primary_key'], $row[$this->primary_key]);
515518
}
516519
}
517520
}

0 commit comments

Comments
 (0)