【发布时间】:2015-06-30 14:19:09
【问题描述】:
在我的应用程序中,我有带有相关翻译的产品实体(不同语言的描述)、配件(产品列表),最后是价格实体。有欧元价格表,美元,澳大利亚和适当的价格条目是通过使用当前价格表ID检索的。
class Product extends \yii\db\ActiveRecord
{
...
public function getPrice()
{
$supplier = Supplier::getCurrent();
return $this->hasOne(ProductPrice::className(), ['IDProduct' => 'IDProduct'])
->onCondition(['PriceListID' => ... getCurrentPricelistID()]);
}
...
}
下面的查询检索具有填充价格、配件和翻译属性的产品条目数组。
$query = Product::find()
->where($conditions)
->with('translation', 'accessories', 'price')
->asArray()
->all();
我需要过滤掉价格为空的产品条目。这样一些价目表(例如澳大利亚的价目表)的产品将比其他价目表少,因为有些产品不在该国家/地区销售。我该怎么做?
【问题讨论】:
标签: database activerecord yii2 relationship