Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
imi
imi
提交
4648e8c7
imi
项目概览
imi
/
imi
10 个月 前同步成功
通知
53
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
imi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4648e8c7
编写于
5月 24, 2021
作者:
weixin_47267244
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持为查询出来的关联模型指定字段
上级
59077366
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
110 addition
and
0 deletion
+110
-0
doc/components/orm/relation/index.md
doc/components/orm/relation/index.md
+28
-0
src/Model/Annotation/Relation/ManyToMany.php
src/Model/Annotation/Relation/ManyToMany.php
+7
-0
src/Model/Annotation/Relation/OneToMany.php
src/Model/Annotation/Relation/OneToMany.php
+7
-0
src/Model/Annotation/Relation/OneToOne.php
src/Model/Annotation/Relation/OneToOne.php
+7
-0
src/Model/Annotation/Relation/PolymorphicManyToMany.php
src/Model/Annotation/Relation/PolymorphicManyToMany.php
+7
-0
src/Model/Annotation/Relation/PolymorphicOneToMany.php
src/Model/Annotation/Relation/PolymorphicOneToMany.php
+7
-0
src/Model/Annotation/Relation/PolymorphicOneToOne.php
src/Model/Annotation/Relation/PolymorphicOneToOne.php
+7
-0
src/Model/Annotation/Relation/PolymorphicToMany.php
src/Model/Annotation/Relation/PolymorphicToMany.php
+7
-0
src/Model/Annotation/Relation/PolymorphicToOne.php
src/Model/Annotation/Relation/PolymorphicToOne.php
+7
-0
src/Model/Relation/Query.php
src/Model/Relation/Query.php
+26
-0
未找到文件。
doc/components/orm/relation/index.md
浏览文件 @
4648e8c7
...
@@ -28,6 +28,10 @@
...
@@ -28,6 +28,10 @@
`@OneToMany(model="模型类名", order="排序规则字符串,例:age desc, id desc")`
`@OneToMany(model="模型类名", order="排序规则字符串,例:age desc, id desc")`
为查询出来的模型指定字段:
`@OneToMany(model="模型类名", order="排序规则字符串,例:age desc, id desc", fields={"字段1", "字段2"})`
### @ManyToMany
### @ManyToMany
多对多关系声明
多对多关系声明
...
@@ -36,6 +40,10 @@
...
@@ -36,6 +40,10 @@
`@ManyToMany(model="关联模型", middle="中间模型类名", rightMany="属性名,赋值为关联的模型对象列表", order="排序规则字符串,例:age desc, id desc")`
`@ManyToMany(model="关联模型", middle="中间模型类名", rightMany="属性名,赋值为关联的模型对象列表", order="排序规则字符串,例:age desc, id desc")`
为查询出来的模型指定字段:
`@ManyToMany(model="关联模型", middle="中间模型类名", rightMany="属性名,赋值为关联的模型对象列表", order="排序规则字符串,例:age desc, id desc", fields={"字段1", "字段2"})`
### @PolymorphicOneToOne
### @PolymorphicOneToOne
多态一对一关系声明
多态一对一关系声明
...
@@ -44,6 +52,10 @@
...
@@ -44,6 +52,10 @@
`@PolymorphicOneToOne(model="关联模型", type="多态类型字段名", typeValue="多态类型值")`
`@PolymorphicOneToOne(model="关联模型", type="多态类型字段名", typeValue="多态类型值")`
为查询出来的模型指定字段:
`@PolymorphicOneToOne(model="关联模型", type="多态类型字段名", typeValue="多态类型值", fields={"字段1", "字段2"})`
### @PolymorphicOneToMany
### @PolymorphicOneToMany
多态一对多关系声明
多态一对多关系声明
...
@@ -52,6 +64,10 @@
...
@@ -52,6 +64,10 @@
`@PolymorphicOneToMany(model="关联模型", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc")`
`@PolymorphicOneToMany(model="关联模型", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc")`
为查询出来的模型指定字段:
`@PolymorphicOneToMany(model="关联模型", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc", fields={"字段1", "字段2"})`
### @PolymorphicManyToMany
### @PolymorphicManyToMany
多态多对多关系声明
多态多对多关系声明
...
@@ -60,6 +76,10 @@
...
@@ -60,6 +76,10 @@
`@PolymorphicManyToMany(model="关联模型", middle="中间模型类名", rightMany="属性名,赋值为关联的模型对象列表", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc")`
`@PolymorphicManyToMany(model="关联模型", middle="中间模型类名", rightMany="属性名,赋值为关联的模型对象列表", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc")`
为查询出来的模型指定字段:
`@PolymorphicManyToMany(model="关联模型", middle="中间模型类名", rightMany="属性名,赋值为关联的模型对象列表", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc", fields={"字段1", "字段2"})`
### @PolymorphicToOne
### @PolymorphicToOne
用于多态一对一、一对多关联被关联的模型中使用,查询对应的左侧模型
用于多态一对一、一对多关联被关联的模型中使用,查询对应的左侧模型
...
@@ -70,6 +90,10 @@
...
@@ -70,6 +90,10 @@
`@PolymorphicToOne(model="关联模型", modelField="关联的模型用于关联的字段", field="当前模型用于关联的字段", type="多态类型字段名", typeValue="多态类型值")`
`@PolymorphicToOne(model="关联模型", modelField="关联的模型用于关联的字段", field="当前模型用于关联的字段", type="多态类型字段名", typeValue="多态类型值")`
为查询出来的模型指定字段:
`@PolymorphicToOne(model="关联模型", modelField="关联的模型用于关联的字段", field="当前模型用于关联的字段", type="多态类型字段名", typeValue="多态类型值", fields={"字段1", "字段2"})`
### @PolymorphicToMany
### @PolymorphicToMany
用于多态多对多关联被关联的模型中使用,查询对应的左侧模型列表
用于多态多对多关联被关联的模型中使用,查询对应的左侧模型列表
...
@@ -82,6 +106,10 @@
...
@@ -82,6 +106,10 @@
`@PolymorphicToMany(model="关联模型", modelField="关联的模型用于关联的字段", field="当前模型用于关联的字段", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc")`
`@PolymorphicToMany(model="关联模型", modelField="关联的模型用于关联的字段", field="当前模型用于关联的字段", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc")`
为查询出来的模型指定字段:
`@PolymorphicToMany(model="关联模型", modelField="关联的模型用于关联的字段", field="当前模型用于关联的字段", type="多态类型字段名", typeValue="多态类型值", order="排序规则字符串,例:age desc, id desc", fields={"字段1", "字段2")`
### @JoinFrom
### @JoinFrom
一对一、一对多声明中,指定左表与右表关联用的字段名
一对一、一对多声明中,指定左表与右表关联用的字段名
...
...
src/Model/Annotation/Relation/ManyToMany.php
浏览文件 @
4648e8c7
...
@@ -46,4 +46,11 @@ class ManyToMany extends RelationBase
...
@@ -46,4 +46,11 @@ class ManyToMany extends RelationBase
* @var string
* @var string
*/
*/
public
$order
;
public
$order
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Annotation/Relation/OneToMany.php
浏览文件 @
4648e8c7
...
@@ -37,4 +37,11 @@ class OneToMany extends RelationBase
...
@@ -37,4 +37,11 @@ class OneToMany extends RelationBase
* @var string
* @var string
*/
*/
public
$order
;
public
$order
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Annotation/Relation/OneToOne.php
浏览文件 @
4648e8c7
...
@@ -28,4 +28,11 @@ class OneToOne extends RelationBase
...
@@ -28,4 +28,11 @@ class OneToOne extends RelationBase
* @var string
* @var string
*/
*/
public
$model
;
public
$model
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Annotation/Relation/PolymorphicManyToMany.php
浏览文件 @
4648e8c7
...
@@ -60,4 +60,11 @@ class PolymorphicManyToMany extends RelationBase
...
@@ -60,4 +60,11 @@ class PolymorphicManyToMany extends RelationBase
* @var string
* @var string
*/
*/
public
$order
;
public
$order
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Annotation/Relation/PolymorphicOneToMany.php
浏览文件 @
4648e8c7
...
@@ -51,4 +51,11 @@ class PolymorphicOneToMany extends RelationBase
...
@@ -51,4 +51,11 @@ class PolymorphicOneToMany extends RelationBase
* @var string
* @var string
*/
*/
public
$order
;
public
$order
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Annotation/Relation/PolymorphicOneToOne.php
浏览文件 @
4648e8c7
...
@@ -42,4 +42,11 @@ class PolymorphicOneToOne extends RelationBase
...
@@ -42,4 +42,11 @@ class PolymorphicOneToOne extends RelationBase
* @var mixed
* @var mixed
*/
*/
public
$typeValue
;
public
$typeValue
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Annotation/Relation/PolymorphicToMany.php
浏览文件 @
4648e8c7
...
@@ -74,4 +74,11 @@ class PolymorphicToMany extends RelationBase
...
@@ -74,4 +74,11 @@ class PolymorphicToMany extends RelationBase
* @var string
* @var string
*/
*/
public
$order
;
public
$order
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Annotation/Relation/PolymorphicToOne.php
浏览文件 @
4648e8c7
...
@@ -56,4 +56,11 @@ class PolymorphicToOne extends RelationBase
...
@@ -56,4 +56,11 @@ class PolymorphicToOne extends RelationBase
* @var mixed
* @var mixed
*/
*/
public
$typeValue
;
public
$typeValue
;
/**
* 为查询出来的模型指定字段.
*
* @var string[]|null
*/
public
$fields
=
null
;
}
}
src/Model/Relation/Query.php
浏览文件 @
4648e8c7
...
@@ -5,6 +5,7 @@ namespace Imi\Model\Relation;
...
@@ -5,6 +5,7 @@ namespace Imi\Model\Relation;
use
Imi\Bean\Annotation\AnnotationManager
;
use
Imi\Bean\Annotation\AnnotationManager
;
use
Imi\Bean\BeanFactory
;
use
Imi\Bean\BeanFactory
;
use
Imi\Db\Db
;
use
Imi\Db\Db
;
use
Imi\Db\Query\Interfaces\IQuery
;
use
Imi\Event\Event
;
use
Imi\Event\Event
;
use
Imi\Model\Annotation\Relation\AutoSelect
;
use
Imi\Model\Annotation\Relation\AutoSelect
;
use
Imi\Model\Annotation\Relation\RelationBase
;
use
Imi\Model\Annotation\Relation\RelationBase
;
...
@@ -116,7 +117,12 @@ abstract class Query
...
@@ -116,7 +117,12 @@ abstract class Query
}
}
else
else
{
{
/** @var IQuery $query */
$query
=
$modelClass
::
query
()
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
$query
=
$modelClass
::
query
()
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
if
(
$annotation
->
fields
)
{
$query
->
field
(
...
$annotation
->
fields
);
}
Event
::
trigger
(
$eventName
.
'.BEFORE'
,
[
Event
::
trigger
(
$eventName
.
'.BEFORE'
,
[
'model'
=>
$model
,
'model'
=>
$model
,
'propertyName'
=>
$propertyName
,
'propertyName'
=>
$propertyName
,
...
@@ -170,7 +176,12 @@ abstract class Query
...
@@ -170,7 +176,12 @@ abstract class Query
$model
->
$propertyName
=
new
ArrayList
(
$modelClass
);
$model
->
$propertyName
=
new
ArrayList
(
$modelClass
);
if
(
null
!==
$model
->
$leftField
)
if
(
null
!==
$model
->
$leftField
)
{
{
/** @var IQuery $query */
$query
=
$modelClass
::
query
()
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
$query
=
$modelClass
::
query
()
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
if
(
$annotation
->
fields
)
{
$query
->
field
(
...
$annotation
->
fields
);
}
if
(
$annotation
->
order
)
if
(
$annotation
->
order
)
{
{
$query
->
orderRaw
(
$annotation
->
order
);
$query
->
orderRaw
(
$annotation
->
order
);
...
@@ -292,7 +303,12 @@ abstract class Query
...
@@ -292,7 +303,12 @@ abstract class Query
}
}
else
else
{
{
/** @var IQuery $query */
$query
=
$modelClass
::
query
()
->
where
(
$annotation
->
type
,
'='
,
$annotation
->
typeValue
)
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
$query
=
$modelClass
::
query
()
->
where
(
$annotation
->
type
,
'='
,
$annotation
->
typeValue
)
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
if
(
$annotation
->
fields
)
{
$query
->
field
(
...
$annotation
->
fields
);
}
Event
::
trigger
(
$eventName
.
'.BEFORE'
,
[
Event
::
trigger
(
$eventName
.
'.BEFORE'
,
[
'model'
=>
$model
,
'model'
=>
$model
,
'propertyName'
=>
$propertyName
,
'propertyName'
=>
$propertyName
,
...
@@ -346,7 +362,12 @@ abstract class Query
...
@@ -346,7 +362,12 @@ abstract class Query
$model
->
$propertyName
=
$modelPropery
=
new
ArrayList
(
$modelClass
);
$model
->
$propertyName
=
$modelPropery
=
new
ArrayList
(
$modelClass
);
if
(
null
!==
$model
->
$leftField
)
if
(
null
!==
$model
->
$leftField
)
{
{
/** @var IQuery $query */
$query
=
$modelClass
::
query
()
->
where
(
$annotation
->
type
,
'='
,
$annotation
->
typeValue
)
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
$query
=
$modelClass
::
query
()
->
where
(
$annotation
->
type
,
'='
,
$annotation
->
typeValue
)
->
where
(
$rightField
,
'='
,
$model
->
$leftField
);
if
(
$annotation
->
fields
)
{
$query
->
field
(
...
$annotation
->
fields
);
}
if
(
$annotation
->
order
)
if
(
$annotation
->
order
)
{
{
$query
->
orderRaw
(
$annotation
->
order
);
$query
->
orderRaw
(
$annotation
->
order
);
...
@@ -405,7 +426,12 @@ abstract class Query
...
@@ -405,7 +426,12 @@ abstract class Query
}
}
else
else
{
{
/** @var IQuery $query */
$query
=
$modelClass
::
query
()
->
where
(
$leftField
,
'='
,
$model
->
$rightField
);
$query
=
$modelClass
::
query
()
->
where
(
$leftField
,
'='
,
$model
->
$rightField
);
if
(
$annotationItem
->
fields
)
{
$query
->
field
(
...
$annotationItem
->
fields
);
}
Event
::
trigger
(
$eventName
.
'.BEFORE'
,
[
Event
::
trigger
(
$eventName
.
'.BEFORE'
,
[
'model'
=>
$model
,
'model'
=>
$model
,
'propertyName'
=>
$propertyName
,
'propertyName'
=>
$propertyName
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录