A
A
alehandroWEB2019-03-13 10:40:14
Yii
alehandroWEB, 2019-03-13 10:40:14

How to get the value of a model method as a result of an ActiveRecord fetch?

In order to get the data of the associated table as a result of the selection, you need to use with(), but how to get the value of a regular method, for example, this one:

public function getExample(){
return 'что-то';
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-03-13
@slo_nik

Good morning.

$model = new Model;
$model->getExample;

M
Maxim Timofeev, 2019-03-13
@webinar

In order to get the data of the associated table as a result of the selection, you need to use with()

no, this is not a true statement, you need to use relationships, and with is needed to load them eagerly.
As I understand it, you need something like (for a hasOne connection)
$myModel->relationName->example;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question