@@ -462,6 +462,9 @@ public function with($relationship)
462
462
463
463
public function relate ($ row )
464
464
{
465
+ if (empty ($ row ))
466
+ return $ row ;
467
+
465
468
foreach ($ this ->belongs_to as $ key => $ value )
466
469
{
467
470
if (is_string ($ value ))
@@ -477,14 +480,14 @@ public function relate($row)
477
480
478
481
if (in_array ($ relationship , $ this ->_with ))
479
482
{
480
- $ this ->load ->model ($ options ['model ' ]);
483
+ $ this ->load ->model ($ options ['model ' ], $ relationship );
481
484
if (is_object ($ row ))
482
485
{
483
- $ row ->{$ relationship } = $ this ->{$ options [ ' model ' ] }->get ($ row ->{$ options ['primary_key ' ]});
486
+ $ row ->{$ relationship } = $ this ->{$ relationship }->get ($ row ->{$ options ['primary_key ' ]});
484
487
}
485
488
else
486
489
{
487
- $ row [$ relationship ] = $ this ->{$ options [ ' model ' ] }->get ($ row [$ options ['primary_key ' ]]);
490
+ $ row [$ relationship ] = $ this ->{$ relationship }->get ($ row [$ options ['primary_key ' ]]);
488
491
}
489
492
}
490
493
}
@@ -504,14 +507,14 @@ public function relate($row)
504
507
505
508
if (in_array ($ relationship , $ this ->_with ))
506
509
{
507
- $ this ->load ->model ($ options ['model ' ]);
510
+ $ this ->load ->model ($ options ['model ' ], $ relationship );
508
511
if (is_object ($ row ))
509
512
{
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 });
511
514
}
512
515
else
513
516
{
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 ]);
515
518
}
516
519
}
517
520
}
0 commit comments