I have 2 tables: Estimate and Activity.
-
An estimate can have many activity
-
An activity belongs to 1 estimate
I am trying to get all activity to populate a dropdown which has ‘activity name - estimate name’ using the following:
$activities = Activity::getAll();
# inside Activity.php
# this works
public static function getAll() {
return self::find()
->select(['{{activity}}.id, CONCAT( {{activity}}.name, \' - \', {{estimate}}.name ) as description'])
->join('INNER JOIN', 'estimate', 'estimate.id = activity.estimate_id')
->asArray()->all();
}
# this give PHP Notice 'yii\base\ErrorException' with message 'Undefined index: estimate_id' <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' /> WHY ??
public static function getAll() {
return self::find()
->select(['{{activity}}.id, CONCAT( {{activity}}.name, \' - \', {{estimate}}.name ) as description'])
->joinWith('estimate', true, 'INNER JOIN')
->asArray()->all();
}
# this is OK if i dont eager loading
public static function getAll() {
return self::find()
->select(['{{activity}}.id, CONCAT( {{activity}}.name, \' - \', {{estimate}}.name ) as description'])
->joinWith('estimate', false, 'INNER JOIN')
->asArray()->all();
}
Please help me to understand why Eager Loading breaks ?