Таблица my_users_table имеет поля: id, name, status
Таблица my_comments_table имеет поля: id, user_id, body, status
Код: Выделить всё
class User extends ActiveRecord {
public static function tableName() { return 'my_users_table'; }
public function getComments() { return $this->hasMany( Comments::class, ['user_id' => 'id'] ); }
}
class CommentQuery extends ActiveQuery {
public function active() {
return $this->andWhere( ['status' => 1] );
}
...
}
class Comment extends ActiveRecord {
public static function tableName() { return 'my_comments_table''; }
public static function find() { return new CommentQuery(get_called_class()); }
}
Код: Выделить всё
$query = User::find()->innerJoinWith( [
'comments' => function( CommentQuery $q ) {
$q->active();
}
], false )->active();
echo $query->createCommand()->getRawSql();
Естественно это не работает, потому что нет чёткого понятия к какой таблице относиться status = 1 выражение.
Как решить эту проблему по красоте без костылей?