public static function belongsTo($name, $params) { self::validateParams($params); $class = $params['class']; $localKey = $params['foreignKey']; $foreignKey = Arrays::getValue($params, 'referencedColumn') ?: MetaModelCache::getMetaInstance(AutoloadNamespaces::getModelNamespace() . $class)->getIdName(); return self::newRelation($name, $localKey, $foreignKey, false, $params); }
/** * @return Model */ public function getRelationModelObject() { return MetaModelCache::getMetaInstance(AutoloadNamespaces::getModelNamespace() . $this->class); }
public function getClassNamespace() { $parts = explode('\\', $this->namespace); $parts = Arrays::map($parts, 'ucfirst'); $modelNamespace = trim(AutoloadNamespaces::getModelNamespace(), '\\'); if (!Strings::startsWith($this->namespace, $modelNamespace)) { $parts = array_merge(array($modelNamespace), $parts); } $parts = Arrays::filterNotBlank($parts); return implode('\\', $parts); }
public function configure() { $defaultNamespace = trim(AutoloadNamespaces::getModelNamespace(), '\\'); $this->setName('ouzo:model_generator')->addArgument('table', InputArgument::REQUIRED, 'Table name.')->addOption('class', 'c', InputOption::VALUE_REQUIRED, 'Class name. If not specified class name is generated based on table name.')->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'Class file path. If not specified namespace and class name is used.')->addOption('namespace', 's', InputOption::VALUE_REQUIRED, 'Class namespace (e.g \'Model\\MyModel\'). Hint: Remember to escape backslash (\\\\)!', $defaultNamespace)->addOption('remove-prefix', 'p', InputOption::VALUE_REQUIRED, 'Remove prefix from table name when generating class name.', 't')->addOption('output-only', 'o', InputOption::VALUE_NONE, 'Only displaying generated model class.')->addOption('short-arrays', 'a', InputOption::VALUE_NONE, 'Generate model class with short arrays. (PHP 5.4).'); }