我和Jobeet一起学习Symfony和Doctrine。我想添加一些修改。 默认是: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/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), notnull: true, unique: true }
nametwo: { type: string(255), notnull: true, unique: true }
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer, notnull: true }
nametwo_id: { type: integer, notnull: true }
(...)
relations:
JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs }
JobeetCategory: { onDelete: CASCADE, local: nametwo_id, foreign: id, foreignAlias: JobeetJobsTwo }
我怎么能以“nametwo”的形式出现?我将有两个列表选择(category_id(已经)和nametwo_id:)
答案 0 :(得分:0)
您想在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