File tree 3 files changed +10
-5
lines changed
3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -139,17 +139,16 @@ public function __get ($name) {
139
139
$ modelName = $ this ->relations [$ name ][1 ];
140
140
switch ($ relationType ) {
141
141
case 'hasone ' :
142
+ $ key = isset ($ this ->relations [$ name ][2 ]) ? $ this ->relations [$ name ][2 ] : $ name ;
142
143
$ obj = new $ modelName ;
143
144
$ obj ->returnType = $ this ->returnType ;
144
- $ this ->data [$ name ] = $ obj ->byId ($ this ->data [$ name ]);
145
- return $ this ->data [$ name ];
145
+ return $ this ->data [$ name ] = $ obj ->byId ($ this ->data [$ key ]);
146
146
break ;
147
147
case 'hasmany ' :
148
148
$ key = $ this ->relations [$ name ][2 ];
149
149
$ obj = new $ modelName ;
150
150
$ obj ->returnType = $ this ->returnType ;
151
- $ this ->data [$ name ] = $ obj ->where ($ key , $ this ->data [$ this ->primaryKey ])->get ();
152
- return $ this ->data [$ name ];
151
+ return $ this ->data [$ name ] = $ obj ->where ($ key , $ this ->data [$ this ->primaryKey ])->get ();
153
152
break ;
154
153
default :
155
154
break ;
Original file line number Diff line number Diff line change @@ -129,6 +129,11 @@ function createTable ($name, $data) {
129
129
exit ;
130
130
}
131
131
132
+ $ product = product::with ('user ' )->byId (5 );
133
+ if (!is_object ($ product ->data ['user ' ])) {
134
+ echo "Error in with processing in getOne object " ;
135
+ exit ;
136
+ }
132
137
133
138
$ products = product::ArrayBuilder ()->with ('userId ' )->get (2 );
134
139
if (!is_array ($ products [0 ]['userId ' ]) || !is_array ($ products [1 ]['userId ' ])) {
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ class product extends dbObject {
16
16
'productName ' => Array ('text ' ,'required ' )
17
17
);
18
18
protected $ relations = Array (
19
- 'userId ' => Array ("hasOne " , "user " )
19
+ 'userId ' => Array ("hasOne " , "user " ),
20
+ 'user ' => Array ("hasOne " , "user " , "userId " )
20
21
);
21
22
22
23
public function last () {
You can’t perform that action at this time.
0 commit comments