@@ -15,6 +15,7 @@ class PartialResult
15
15
protected $ database ;
16
16
protected $ route ;
17
17
protected $ multiresult = false ;
18
+ protected $ resolution = null ;
18
19
19
20
public function __construct (Model $ source )
20
21
{
@@ -25,8 +26,18 @@ public function __construct(Model $source)
25
26
$ this ->database = $ source ->_data ->getDatabase ();
26
27
}
27
28
29
+ public function __call ($ var , $ args )
30
+ {
31
+ $ obj = $ this ->resolve ();
32
+
33
+ return call_user_func_array (array ($ obj , $ var ), $ args );
34
+ }
35
+
28
36
public function __get ($ var )
29
37
{
38
+ if ($ this ->resolution ) return $ this ->resolution ->{$ var };
39
+ if ($ var == '_ ' ) return $ this ->resolve ();
40
+
30
41
if (array_key_exists ($ var , $ this ->currentSchema ['columns ' ]))
31
42
{
32
43
// We have column data, resolve!
@@ -53,26 +64,31 @@ public function __get($var)
53
64
54
65
public function resolve ($ var = null )
55
66
{
56
- // Resolve down to a real Model object, then call __get on it.
57
- $ ids = $ this ->resolveState ();
58
-
59
- $ results = Model::factoryObjectCache ($ ids , $ this ->currentTable , $ this ->database );
60
-
61
- if ($ this ->multiresult && !$ results instanceof Collection)
67
+ if (!$ this ->resolution )
62
68
{
63
- $ results = new Collection ([$ results ]);
69
+ // Resolve down to a real Model object, then call __get on it.
70
+ $ ids = $ this ->resolveState ();
71
+
72
+ $ results = Model::factoryObjectCache ($ ids , $ this ->currentTable , $ this ->database );
73
+
74
+ if ($ this ->multiresult && !$ results instanceof Collection)
75
+ {
76
+ $ results = new Collection ([$ results ]);
77
+ }
78
+
79
+ if (!$ this ->multiresult && $ results instanceof Collection && $ results ->count () == 1 )
80
+ {
81
+ $ results = $ results [0 ];
82
+ }
83
+
84
+ $ this ->resolution = $ results ;
64
85
}
65
86
66
- if (!$ this ->multiresult && $ results instanceof Collection && $ results ->count () == 1 )
67
- {
68
- $ results = $ results [0 ];
69
- }
70
-
71
87
if (!is_null ($ var ))
72
88
{
73
- return $ results ->{$ var };
89
+ return $ this -> resolution ->{$ var };
74
90
}
75
- return $ results ;
91
+ return $ this -> resolution ;
76
92
}
77
93
78
94
protected $ joinCount = 0 ;
@@ -138,8 +154,6 @@ public function pushM2M($col, $target)
138
154
$ key2 = 'join_ ' . ++$ this ->joinCount ;
139
155
$ key2a = $ key2 . 'a ' ;
140
156
141
- var_dump ($ target );
142
-
143
157
$ this ->route [] =
144
158
'Join ` ' . Schema::underscoreCase ($ target ['pivot ' ]) . '` as ' . $ key2a . ' on ' . $ key . '.id = ' . $ key2a . '.` ' . $ target ['id ' ] . '` ' ;
145
159
;
0 commit comments