/** * @return string */ public static function tableAlias() { if (static::$_tableAlias) { return static::$_tableAlias; } $classInfo = new ReflectionClass(get_called_class()); return Inflector::tableize($classInfo->getShortName()); }
/** * Returns an array of owned objects. * * @param string $model Name of the model. * @param aray $options Optional relation options. * * @return array */ public function hasMany($model, $options = []) { $options = static::getRelationInfo($model, $options); if (!isset($options['localKey'])) { $options['localKey'] = 'id'; } if (!isset($options['foreignKey'])) { $options['foreignKey'] = Inflector::foreignKey(static::tableName(false)); } return $options['model']::select()->where("{$options['foreignKey']} = :foreignKey")->setParameter('foreignKey', $this->{$options['localKey']})->mergeNextWhere(); }