- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
最佳答案
Active Query表示与 Active Record 关联的数据库查询类(class)。它通常用于覆盖特定模型的默认 find()
方法,用于在发送到 DB 之前生成查询:
class OrderQuery extends ActiveQuery
{
public function payed()
{
return $this->andWhere(['status' => 1]);
}
public function big($threshold = 100)
{
return $this->andWhere(['>', 'subtotal', $threshold]);
}
}
如果你之前使用过 Yii 1 那么这就是替换 Yii 1.x Named Scopes 的东西在 Yii2 中。您所要做的就是覆盖 model 类中的 find()
方法以使用上面的 ActiveQuery 类:
// This will be auto generated by gii if 'Generate ActiveQuery' is selected
public static function find()
{
return new \app\models\OrderQuery(get_called_class());
}
然后你可以这样使用它:
$payed_orders = Order::find()->payed()->all();
$very_big_orders = Order::find()->big(999)->all();
$big_payed_orders = Order::find()->big()->payed()->all();
上面定义的相同 ActiveQuery 类的不同用例是在相关模型 类中定义关系数据 时使用它,例如:
class Customer extends \yii\db\ActiveRecord
{
...
public function getPayedOrders()
{
return $this->hasMany(Order::className(),['customer_id' => 'id'])->payed();
}
}
然后您可以通过以下方式为客户加载他们各自的已付款订单:
$customers = Customer::find()->with('payedOrders')->all();
关于php - Yii2 : ActiveQuery Example and what is the reason to generate ActiveQuery class separately in Gii?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31948917/
我正在编写一个节点应用程序,我想在其中混合 Reason 和原始 JavaScript。 This section在 bucklescript 文档中对其进行了描述 When user has an
为了将现有的基于 JS 的 WebUI 重构为 ReasonML,我试图嵌入一些重构的代码。目前,我通过将所有 ReasonML 代码(到目前为止)嵌入到 iframe 中来做到这一点。 . 空间非常
我正在尝试设置 RabbitMQ 以根据死亡原因通过死信交换路由消息(“x-death.reason”或“x-first-death-reason”都可以)。 我的理解是,当消息被发送到 DLX 时,
这是我的代码: public class FunctionalityCheckTest1 { InfModel infModel; Model model = ModelFactory
昨天我设法成功运行命令 expo build:ios 但今天早上它不起作用,我在输入凭据后收到以下错误消息: Trying to authenticate with Apple Developer P
我在 Klarna 预测试中得到了这个推理题。请帮我解决这个问题。 Question is in image 最佳答案 你是正确的 'B' 是答案1).中心 3 点,即第 3 列将保持不变2).第4列
在 JavaScript 中,你可以加入一个字符串数组,例如: fruits = ["orange", "apple", "banana"]; joined = fruits.join(", ");
当我使用“java -ea A”运行以下代码时,会触发断言更正,但我没有看到第二个参数。 public class A { public A() { assert 1==2,
我目前正在尝试原因并遇到我不理解的错误 这是我的代码: let mult = (x:float, y:float):float => x * y; 使用BuckleScript进行编译时,出现以下错误
发生了奇怪的事情。 当使用 url 调用以下 servlet 时:http://localhost:8080/Football/InsertTeam?p1_name=hkh&p2_name=klhjk
一些已经开始出现在我的代码中的东西是: {if (condition) { ; } else { ; }} ; 基本上我只想要 Child如果条件为真则渲染
首先我是自定义 TFS 的新手,我的 TFS 团队项目是 Microsoft Visual Studio Scrum 2013 的 99% vanilla 模板。所以我认为我的问题对某些人来说可能是显
我正在学习 reasonml 并且对此感到非常兴奋。我在 typescript react 代码中经常做的事情是: type Props = React.HTMLProps & { foo: bool
我在这里读过另一篇关于SO的文章,在可能的情况下,您不应该为标签生成成员(member)的。我想知道这可能是什么 DRAWBACKS ? 我说的好处是提高性能,对吗?还要别的吗? 我有一个带有100个
我试图使用 Int32 库编写一些代码,但我遇到了类型错误: let x : int = 7; Int32.abs(x) This has type: int But somewhere want
我是第一次探索 ReScript。我想使用记录类型作为我的键类型来构建 HashMap ,并且我正在寻找有关实现哈希函数的指导。 这是我的 ReScript 代码: type pointer = {
我想我是在问这个设计决定背后的基本原理。 数组可变的原因在默认情况下不可变的其他数据结构(列表、记录、散列图、集合)中显得异常突出。 这是有原因的吗?是否有不可变的替代方案? 最佳答案 确实没有“原因
在学习函数式编程时,我不断遇到“原因”这个术语,尤其是在纯函数和/或引用透明性的背景下。有人能解释一下这到底是什么意思吗? 最佳答案 通常,在编写程序时,您的工作不仅仅只是编写代码,您还想了解代码所展
考虑到以下人为的示例,是否可以编写一个可以处理具有 a 属性的任何记录的 get 函数? type type_one = {a: int} type type_two = {a: int, b: in
考虑到以下人为的示例,是否可以编写一个可以处理具有 a 属性的任何记录的 get 函数? type type_one = {a: int} type type_two = {a: int, b: in
我是一名优秀的程序员,十分优秀!