I'm testing CakePHP 3.0-RC1 for possible use on a new project. After installing, configuring and creating two (yes, two) database tables, I ran 'bake all' against both tables.
After dealing with the spurious foreign key references in the model (a foreign key defined as the primary key referencing itself? C'mon, now, Bakers!) I am hitting this error:
Error: Method Cake\ORM\Query::__toString() must not throw an exception File /srv/www/htdocs/wmcb/cake/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php Line: 193
Not my code. ;)
The offending table definition:
-- -----------------------------------------------------
-- Table `ISOCountryCodes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iso_country_codes` (
`iso_country_code_id` VARCHAR(4) CHARACTER SET utf8 NOT NULL ,
`iso_country_name` VARCHAR(64) CHARACTER SET utf8 NOT NULL ,
`iso_country_name_french` VARCHAR(64) CHARACTER SET utf8 NOT NULL ,
PRIMARY KEY (`iso_country_code_id`)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8
COMMENT = 'Look-up table of ISO 3166-1 Country Names and Codes'
;
The IsoCountryCodesController index method, as generated by bake:
/**
* Index method
*
* @return void
*/
public function index()
{
$this->paginate = [
'contain' => ['IsoCountryCodes']
];
$this->set('isoCountryCodes', $this->paginate($this->IsoCountryCodes));
$this->set('_serialize', ['isoCountryCodes']);
}
And the initialize method from IsoCountryCodesTable.php:
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
$this->table('iso_country_codes');
$this->displayField('iso_country_code_id');
$this->primaryKey('iso_country_code_id');
// $this->belongsTo('IsoCountryCodes', ['foreignKey' => iso_country_code_id']);
}
with the reflexive foreign key commented out.
This behaviour holds for both tables.
CakePHP 2.5 works correctly with the same database table definitions.
set()
call with_serialize
for me, but I'm using a recent dev snapshot, maybe you should give that a try too. – ndm