- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
首先,我尝试查看 this ,但我无法使解决方案起作用,因为它涉及数据透视表,而我的没有。我的大脑无法从该解决方案中抽象出解决方案。
我有这个问题:
$orderLines = PurchasingOrderLine::where('season_id', '=', $seasonRecID)
->with('factory')
->with('purchasingFactoryDates.milestone')
->with('divergedColors.purchasingColorDates.milestone')
->get();
所以这是一个很大的关系。
我想按 milestone
的“number”属性对 purchasingFactoryDates
进行排序。
这是此查询的 JSON 响应示例(示例)..
{
id: 1,
season_id: 258,
factory_id: 38,
archived: 0,
created_at: "2016-10-03 00:00:00",
updated_at: "2016-10-04 00:00:00",
factory: {
ID: 38,
name: "testfac",
address: "testadrr",
postCode: "",
city: "Foo",
countryID: 27,
podID: 2,
warehouse_id: 3,
paymentTermID: 11,
factoryCode: "Bazz",
active: 1
},
purchasing_factory_dates: [
{
id: 1,
purchasing_order_line_id: 1,
milestone_id: 1,
milestone_date: "1993-10-22 19:15:51",
milestone_status_id: 2,
created_at: "2016-10-04 07:38:30",
updated_at: "2016-10-18 19:15:51",
milestone: {
id: 1,
name: "test1",
description: null,
number: 1,
created_at: "-0001-11-30 00:00:00",
updated_at: "-0001-11-30 00:00:00"
}
},
.........
关于如何做到这一点有什么想法吗?我不希望整个关系按 Milestone.number
排序,只按 purchasingFactoryDates
排序。
最佳答案
最简单的方法是像这样加入查询:
$orderLines = PurchasingOrderLine::where('season_id', '=', $seasonRecID)
->select('purchasing_order_lines.*')
->join('purchasing_factory_dates', 'purchasing_factory_dates.purchasing_order_line_id', '=', 'purchasing_order_lines.id')
->join('milestone', 'purchasing_factory_dates.milestone_id', '=', 'milestone.id')
->with('factory')
->with('purchasingFactoryDates.milestone')
->with('divergedColors.purchasingColorDates.milestone')
->groupBy('purchasing_order_lines.id')
->orderBy('milestone.number')
->get();
关于php - Laravel 通过嵌套的急切加载关系排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40132447/
我有一个案例,在大多数情况下,对象之间的关系是这样的,因此在关系上预先配置一个渴望(加入)的负载是有意义的。但是现在我遇到了一种情况,我真的不想完成急切的加载。 我是否应该从关系中删除连接负载并将所有
在我的 Grails 项目中,我有以下类: class A { static hasMany = [cs:C] } class B { static hasMany = [cs:C]
想象一下以下简化的 DI 模型: @ApplicationScoped public class A { private B b; @Inject public A(B b)
我使用 MapLoader 将数据从数据存储初始加载到 Hazelcast (InitialLoadMode = EAGER)。我需要从一个物化 View 中加载这些数据,该 View 是为了在加载过
我使用 Hibernate Envers 4.3.10.Final。我有以下两个 JPA 类: public class Factory { private int factoryID;
EJB 似乎被延迟加载 - 每当访问时。 但是,我想急切地初始化它们 - 即每当容器启动时。这是如何实现的(尤其是在 JBoss 中) This topic给出了一些提示,但不是很令人满意。 最佳答案
我是一名优秀的程序员,十分优秀!