File tree Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Expand file tree Collapse file tree 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) {
139139 $ modelName = $ this ->relations [$ name ][1 ];
140140 switch ($ relationType ) {
141141 case 'hasone ' :
142+ $ key = isset ($ this ->relations [$ name ][2 ]) ? $ this ->relations [$ name ][2 ] : $ name ;
142143 $ obj = new $ modelName ;
143144 $ 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 ]);
146146 break ;
147147 case 'hasmany ' :
148148 $ key = $ this ->relations [$ name ][2 ];
149149 $ obj = new $ modelName ;
150150 $ 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 ();
153152 break ;
154153 default :
155154 break ;
Original file line number Diff line number Diff line change @@ -129,6 +129,11 @@ function createTable ($name, $data) {
129129 exit ;
130130}
131131
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+ }
132137
133138$ products = product::ArrayBuilder ()->with ('userId ' )->get (2 );
134139if (!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 {
1616 'productName ' => Array ('text ' ,'required ' )
1717 );
1818 protected $ relations = Array (
19- 'userId ' => Array ("hasOne " , "user " )
19+ 'userId ' => Array ("hasOne " , "user " ),
20+ 'user ' => Array ("hasOne " , "user " , "userId " )
2021 );
2122
2223 public function last () {
You can’t perform that action at this time.
0 commit comments