【问题标题】:Implement self-relations实施自我关系
【发布时间】:2010-12-21 18:06:17
【问题描述】:

谁能给我一个如何实现类自关系的例子?

【问题讨论】:

  • 请详细了解您想要做什么。

标签: doctrine database-relations


【解决方案1】:

你需要这样的东西:

MenuOption:
  tableName: MenuOption
  columns:
    id:
      type: integer(4)
      autoincrement: true
    child_menu_option_id:
      type: integer(4)
      null: true
    ... (more columns)
  relations:
    ChildMenuOptions:
      class: MenuOption
      foreignAlias: News
      foreign: id
      local: child_menu_option_id

一旦你加载了一个 MenuOption 对象,你会像这样引用你的孩子:

$menuOption = Doctrine_Query::create()
  ->from("MenuOption")
  ->where("stuff here")
  ->fetchOne();
$children = $menuOption->ChildMenuOptions; // this will be a Doctrine_Collection object

【讨论】:

    猜你喜欢
    • 2019-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    相关资源
    最近更新 更多