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