| Total Complexity | 6 | 
| Total Lines | 37 | 
| 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 | * @return string | ||
| 16 | * @throws NotSupportedException if multi-column PrimaryKey is used | ||
| 17 | */ | ||
| 18 | public static function primaryKeySingle() | ||
| 19 |     { | ||
| 20 |         if (count(self::primaryKey()) === 1) { | ||
| 21 | return static::tableName() . "_id"; | ||
| 22 | } | ||
| 23 |         throw new NotSupportedException('Not supported for multi-column primary keys'); | ||
| 24 | } | ||
| 25 | |||
| 26 | |||
| 27 |     /** {@inheritdoc} */ | ||
| 28 | public function hasMany($class, $link = null) | ||
| 29 |     { | ||
| 30 | |||
| 31 |         if (empty($link)) { | ||
| 32 | /** @var DActiveRecord $class */ | ||
| 33 | $link = [$class::primaryKeySingle() => $class::primaryKeySingle()]; | ||
| 34 | } | ||
| 35 | return parent::hasMany($class, $link); | ||
| 36 | } | ||
| 37 | |||
| 38 |     /** {@inheritdoc} */ | ||
| 39 | public function hasOne($class, $link = null) | ||
| 46 | } | ||
| 47 | } |