问题描述
|
我和Jobeet学习Symfony和主义。我想添加一些修改。
默认值为:
http://www.symfony-project.org/jobeet/1_4/Doctrine/zh/03
JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255),notnull: true,unique: true }
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer,notnull: true }
(...)
relations:
JobeetCategory: { onDelete: CASCADE,local: category_id,foreign: id,foreignAlias: JobeetJobs }
如果我去表格(创建新的),我有:
http://www.symfony-project.org/images/jobeet/1_4/03/job.png
类别ID-选择列表
//BaseJobeetJobForm.class.PHP:
\'category_id\' => new sfWidgetFormDoctrineChoice(array(\'model\' => $this->getRelatedModelName(\'JobeetCategory\'),\'add_empty\' => false)),
//sfFormDoctrine.class.PHP:
protected function getRelatedModelName($alias)
{
$table = Doctrine_Core::getTable($this->getModelName());
if (!$table->hasRelation($alias))
{
throw new invalidargumentexception(sprintf(\'The \"%s\" model has to \"%s\" relation.\',$this->getModelName(),$alias));
}
$relation = $table->getRelation($alias);
return $relation[\'class\'];
}
我该怎么做:
JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255),unique: true }
nametwo: { type: string(255),notnull: true }
nametwo_id: { type: integer,notnull: true }
(...)
relations:
JobeetCategory: { onDelete: CASCADE,foreignAlias: JobeetJobs }
JobeetCategory: { onDelete: CASCADE,local: nametwo_id,foreignAlias: JobeetJobsTwo }
我如何以\“ nametwo \”形式显示?我将列出两个列表选项(category_id(已经)和nametwo_id :)
解决方法
您要在jobeetjob和jobeetcategory之间建立两个不同的关系。
您必须明确命名该关系,如下所示:
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer,notnull: true }
nametwo_id: { type: integer,notnull: true } (...)
relations:
JobeetCategoryOne:
class: JobeetCategory
onDelete: CASCADE
local: category_id
foreign: id
foreignAlias: JobeetJobs
JobeetCategoryTwo:
class: JobeetCategory
onDelete: CASCADE
local: nametwo_id,foreign: id,foreignAlias: JobeetJobsTwo