Answer the question
In order to leave comments, you need to log in
How to add a condition on links?
There is a Price class, it is tied to the Product class, in the Product model. In the following way
public function getPrice()
{
return $this->hasMany(Price::className(), ['product_id' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
See, you can go two ways. Make the selection condition single, where you need it.
function ($someCountry = 'Ukraine')
{
$product = Product::findOne(123);
//Запрос ниже выполняться может сколько угодно раз в отличии от $price = $product ->Price();
$price = $product ->getPrice()
->where(['country =:someCountry', [':someCountry' => $someCountry])
->orderBy('id')
->all();
}
class Product extends ActiveRecord
{
public function getBigPrices($someCountry)
{
return $this->hasMany(Price::className(), ['product_id' => 'id'])
->where('country > :someCountry', [':someCountry' => $someCountry])
->orderBy('id');
}
}
$query->where(['country' => USA]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question