File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
jkmvc-orm/src/main/kotlin/net/jkcode/jkmvc/orm Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ interface IOrmRelated : IOrmPersistent
2929 */
3030 fun related (name : String , newed : Boolean = false, vararg columns : String ): Any? ;
3131
32+ /* *
33+ * 获得回调的关联对象
34+ *
35+ * @param name 关联对象名
36+ * @return
37+ */
38+ fun cbRelated (name : String ): Any?
39+
3240 /* *
3341 * 检查是否有关联对象
3442 * 一般只用于一对多 hasMany 的关系
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ abstract class OrmRelated : OrmPersistent() {
4545 if (ormMeta.hasRelation(column))
4646 return related(column, false ) as T ;
4747
48+ // 获得回调的关联对象
49+ if (ormMeta.hasCbRelation(column))
50+ return cbRelated(column) as T ;
51+
4852 return super .get(column, defaultValue);
4953 }
5054
@@ -193,6 +197,27 @@ abstract class OrmRelated : OrmPersistent() {
193197 return _data [name];
194198 }
195199
200+ /* *
201+ * 获得回调的关联对象
202+ *
203+ * @param name 关联对象名
204+ * @return
205+ */
206+ public override fun cbRelated (name : String ): Any? {
207+ if (name !in _data ){
208+ // 获得关联关系
209+ val relation = ormMeta.getCbRelation(name)!! ;
210+
211+ var result = relation.findAllRelated(this )
212+ _data [name] = if (relation.hasMany)
213+ result
214+ else
215+ result.firstOrNull()
216+ }
217+
218+ return _data [name]
219+ }
220+
196221 /* *
197222 * 统计关联对象个数
198223 * 一般只用于一对多 hasMany 的关系
You can’t perform that action at this time.
0 commit comments