ノードからすべての祖先を取得しようとしているときに少し問題が発生しました。
これは私のschema.ymlです:
Constante:
connection: doctrine
tableName: constante
actAs:
NestedSet:
hasManyRoots: true
rootColumnName: parent_id
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
parent_id:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
lft:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
rgt:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
level:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
cod_interno:
type: string(5)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
nombre:
type: string(64)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
そして、これはノード(ルートではない)からすべての祖先を取得しようとしている方法です
$path = Doctrine_Core::getTable('Constante')->find($condicion); // $condicion = 57
$node = $path->getNode();
$isLeaf = $node->isLeaf(); //var_dump throws true
$ancestors = $node->getAncestors(); //var_dump throws false
$isValidNode = $node->isValidNode(); //var_dump throws true
それ$ancestors == false
を反復してすべての先祖を取得することはできないため (単純なブレッドクラムを作成しようとしています)
これは私がDBに保存したものです。これは実際のデータです(テスト目的のみ)
+---------++---------++---------++---------++----------++---------+
|ID ||PARENT_ID||LFT ||RGT ||LEVEL ||NOMBRE |
|---------||---------||---------||---------||----------||---------|
|56 ||56 ||1 ||4 ||0 ||COUNTRY | --> this is root
|57 ||56 ||2 ||3 ||1 ||CANADA | --> child of root
+---------++---------++---------++---------++----------++---------+
これによると、Ancestors が false を返した場合、選択したノードがルートであることを意味します。
運の悪い解決策を探すのに何時間も費やしました。
さらに詳しい情報が必要な場合は、遠慮なくお尋ねください。
編集:表にあるものを入力するときに間違いを犯しました.olivierwのおかげで、これについて警告してくれました.