2011-06-12 79 views
0

我学习Symfony和Doctrine with Jobeet。我想添加aeveral修改。 默认为: 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

更新,现在是好 – 2011-06-12 21:09:49

回答

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 
+0

DXB:我已经编辑你的答案和固定的语法高亮。对于代码示例,所有行都应该添加四个空格,以便SO突出显示它。适当修复。 – 2011-06-14 09:04:37