M
M
My joy2018-02-05 13:02:02
Yii
My joy, 2018-02-05 13:02:02

How to create a link with a condition?

Hi friends.
There is a table of goods (sku):
id, sku, title
And there is a table of prices (sku_costs):
id, sum, datefrom
In the table of prices, the chronology of prices for each product. The current price of the product should be pulled out by the maximum datefrom (datetime) and id.
Question: How can I display this relationship in the search model?
In the Sku model, I declare the relationship like this:

public function getCost()
{
    return $this->hasOne(SkuCosts::className(), ['id' => 'id']);
}

How to correctly add here the extraction of id with the maximum date? Adding orderBy sorts the entire searchModel, and generally doesn't seem relevant to the current task. Correct me if I'm wrong.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question