Use related table field as title in View page

Hello,

How could be used a field from a related table in the title of the View page?

When you want to use another field from the same model there’s no problem, just simply change the field in


$this->title = $model->neededField

But how you do that when the field is not in the current model but in a related table.

I have a table that stores historical prices for products, this table has product_id FK, but I want to put the product’s name on the view and update pages, instead of the product id.

Regards

If model is Price instance and ‘product’ is the relation that link the Product to the price, then:




$this->title = $model->product->nameOfTheProduct



Excellent!, worked like a charm.

Thank you very much.