【问题标题】:getting two column with relation得到两列有关系
【发布时间】:2011-06-12 17:37:07
【问题描述】:

我和 Jobeet 一起学习 Symfony 和 Doctrine。我想添加 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 (already) 和 nametwo_id: )

【问题讨论】:

    标签: php symfony-1.4 doctrine-1.2


    【解决方案1】:

    您想在 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 
    

    【讨论】:

    • dxb:我已经编辑了您的答案并修复了语法突出显示。对于代码示例,所有行都应附加四个空格,以便 SO 突出显示它。妥当修复。
    猜你喜欢
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2021-01-27
    • 2022-06-12
    • 2015-06-27
    • 1970-01-01
    相关资源
    最近更新 更多