| Total Complexity | 7 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class DActiveRecord extends ActiveRecord |
||
| 10 | { |
||
| 11 | /** in case we would need to customize stuff */ |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Get the primary key column as string if the one-column PK |
||
| 15 | * NB! Always use single column Primary-keys! |
||
| 16 | * @return string |
||
| 17 | * @throws NotSupportedException if multi-column PrimaryKey is used |
||
| 18 | */ |
||
| 19 | public static function primaryKeySingle() |
||
| 20 | { |
||
| 21 | if (count(self::primaryKey()) === 1) { |
||
| 22 | return static::tableName() . "_id"; |
||
| 23 | } |
||
| 24 | throw new NotSupportedException('Not supported for multi-column primary keys'); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @return string[]|void |
||
| 29 | * @throws NotSupportedException |
||
| 30 | */ |
||
| 31 | public static function primaryKey() |
||
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | /** {@inheritdoc} */ |
||
| 38 | public function hasMany($class, $link = null) |
||
| 39 | { |
||
| 40 | |||
| 41 | if (empty($link)) { |
||
| 42 | /** @var DActiveRecord $class */ |
||
| 43 | $link = [$class::primaryKeySingle() => $class::primaryKeySingle()]; |
||
| 44 | } |
||
| 45 | return parent::hasMany($class, $link); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** {@inheritdoc} */ |
||
| 49 | public function hasOne($class, $link = null) |
||
| 56 | } |
||
| 57 | } |