kikukawa's diary

都内で活動するシステムエンジニアが書いてます。 興味を持った技術やハマったポイント、自分用メモをつけてます。 最近はweb中心

CakePHPのモデルでfindを実行するとInvalid arguments passedのエラー

CakePHPのモデルでハマったのでメモ。
バージョンは2.2

BarモデルのFindを実行すると下記のようなエラーが表示されました。
原因は、Barの継承元クラスで、public $useTable = falseとしていたのを忘れて、public $useTable = 'bar'を設定し忘れていたから。
useTableを明示的に指定するようにプロジェクト内で強制していたのですが、それをすっかり忘れていました。

Warning Error: array_keys() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2296]

Warning Error: array_filter() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2300]

Warning Error: array_values() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2300]

Warning Error: array_unique() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2378]

Warning Error: array_keys() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2296]

Warning Error: array_filter() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2300]

Warning Error: array_values() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2300]

Warning Error: array_unique() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 2378]

Warning Error: array_unique() expects parameter 1 to be array, null given in [/path/to/Cake/Model/Datasource/DboSource.php, line 1506]

Warning Error: implode(): Invalid arguments passed in [/path/to/Cake/Model/Datasource/DboSource.php, line 1722]

2015-02-25 20:40:18 Critical: Error SQL Query: SELECT  FROM `foo`.`bar` AS `Bar`   WHERE 1 = 1    LIMIT 1
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `foo`.`bar` AS `Bar`   WHERE 1 = 1    LIMIT 1' at line 1
#0 /path/to/Cake/Model/Datasource/DboSource.php(461): PDOStatement->execute(Array)
#1 /path/to/Cake/Model/Datasource/DboSource.php(427): DboSource->_execute('SELECT  FROM `h...', Array)
#2 /path/to/MyLib/Model/Datasource/DboMysqlLog.php(18): DboSource->execute('SELECT  FROM `h...', Array, Array)
#3 /path/to/Cake/Model/Datasource/DboSource.php(671): DboMysqlLog->execute('SELECT  FROM `h...', Array, Array)
#4 /path/to/Cake/Model/Datasource/DboSource.php(1082): DboSource->fetchAll('SELECT  FROM `h...', false)
#5 /path/to/Cake/Model/Model.php(2630): DboSource->read(Object(Bar), Array)
#6 /path/to/app/Console/Command/FooShell.php(18): Model->find()
#7 /path/to/Cake/Console/Shell.php(393): FooShell->main()
#8 /path/to/Cake/Console/ShellDispatcher.php(201): Shell->runCommand(NULL, Array)
#9 /path/to/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
#10 /path/to/app/Console/cake.php(33): ShellDispatcher::run(Array)
#11 {main}