Closed dhoomm closed 7 years ago
This prevents duplicate column names in joins. class SportCar/HeavyCar extends Car the find function should also pass the table name to CarQuery
class SportCar/HeavyCar extends Car
find
return new CarQuery(get_called_class(), ['type' => self::TYPE,'tableName'=> self::tableName()]);.
return new CarQuery(get_called_class(), ['type' => self::TYPE,'tableName'=> self::tableName()]);
Then add a property $tableName to class CarQuery. Then use it in function prepare as
$tableName
class CarQuery
function prepare
$this->andWhere(["$this->tableName.type" => $this->type]);
When creating a join with a table having column name 'type' wont create conflict..
Would you please make a pull request?
created at https://github.com/samdark/yii2-cookbook/pull/148
This prevents duplicate column names in joins.
class SportCar/HeavyCar extends Car
thefind
function should also pass the table name to CarQueryreturn new CarQuery(get_called_class(), ['type' => self::TYPE,'tableName'=> self::tableName()]);
.Then add a property
$tableName
toclass CarQuery
. Then use it infunction prepare
as$this->andWhere(["$this->tableName.type" => $this->type]);
When creating a join with a table having column name 'type' wont create conflict..