0

Can anyone give me an example of how to implement a class self-relation?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Rui Gonçalves
  • 2,423
  • 6
  • 30
  • 42

1 Answers1

1

You need something like this:

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

You'd refer to your children like this once you've loaded a MenuOption object:

$menuOption = Doctrine_Query::create()
  ->from("MenuOption")
  ->where("stuff here")
  ->fetchOne();
$children = $menuOption->ChildMenuOptions; // this will be a Doctrine_Collection object
Chris Williams
  • 11,647
  • 15
  • 60
  • 97