兄弟。奇妙な振る舞いをしました。Laravel 4 ClosureTableパッケージのテストを書いています。
すべてのテストは、さらに使用するために新しいEntity
(または) を作成します。Entitites
たとえば、最初のテストの 1 つ: ClosureTableTestCase::testInsertSingle
. 実行すると、次のようになりました。
Exception: SQLSTATE[HY000]: General error: 1 table pages_closure has no column named 0 (SQL: insert into "pages_closure" ("ancestor", "depth", "descendant", "0", "1", "2") values (?, ?, ?, ?, ?, ?)) (Bindings: array (
0 => '1',
1 => '0',
2 => '1',
3 => '1',
4 => '1',
5 => '0',
))
そしてvar_dump
私に次のように言います:
配列(1) { [0] => 配列(6) { '祖先' => 文字列(1) "1" [0] => 文字列(1) "1" '子孫' => 文字列(1) "1" [1] => 文字列(1) "1" '深さ' => 文字列(1)「0」 [2] => 文字列(1)「0」 } }
ただし、Web インターフェイスを介してエンティティを作成すると、すべて問題ありません。
DB::select($selectQuery);
ターミナル経由でテストを実行すると、呼び出しからエラーが発生します。ご覧のとおり、[0]、[1]、および [2] の追加の配列キーを取得しました。ただし、Web インターフェイスを介してエンティティを作成すると、すべて問題ありません。
エラーは、内部で実行されるこのメソッドにあります:
protected function performInsertNode($descendant, $ancestor)
{
$table = $this->closure;
$ak = static::ANCESTOR;
$dk = static::DESCENDANT;
$dpk = static::DEPTH;
DB::transaction(function() use($table, $ak, $dk, $dpk, $descendant, $ancestor){
$selectQuery = "
SELECT tbl.{$ak} as {$ak}, {$descendant} as {$dk}, tbl.{$dpk}+1 as {$dpk}
FROM {$table} AS tbl
WHERE tbl.{$dk} = {$ancestor}
UNION ALL
SELECT {$descendant}, {$descendant}, 0
";
$results = DB::select($selectQuery);
array_walk($results, function(&$item){ $item = (array)$item; });
var_dump($results);
DB::table($table)->insert($results);
});
}
間違いを指摘してもらえますか?