获取具有关系的两列

发布于 2024-11-15 14:06:49 字数 2101 浏览 3 评论 0原文

我和 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:)

i learn Symfony and Doctrine with Jobeet. I would like add aeveral modifications.
default is:
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 } 

and if i go to form (create new) i have:
http://www.symfony-project.org/images/jobeet/1_4/03/job.png

Category id - choice list

//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'];
  }

how can I do something like:

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 } 

how can i show in form "nametwo"? i will two list choices (category_id (already) and nametwo_id: )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒路情人 2024-11-22 14:06:49

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

You want to setup two distinct relation between jobeetjob and jobeetcategory.
You have to name distinctly the relation, like this :

    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 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文