samdark / yii2-cookbook

Yii 2.0 Community Cookbook
1.45k stars 297 forks source link

Add tablename to ar-single-table-inheritance #147

Closed dhoomm closed 7 years ago

dhoomm commented 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

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

$this->andWhere(["$this->tableName.type" => $this->type]);

When creating a join with a table having column name 'type' wont create conflict..

samdark commented 7 years ago

Would you please make a pull request?

dhoomm commented 7 years ago

created at https://github.com/samdark/yii2-cookbook/pull/148