Monday, February 25, 2013

Re: Fixture for the model of a HABTM relationship generates invalid SQL

Ok so I guess I found the solution for this...

Before I was getting this error:
    Warning: array_map(): An error occurred while invoking the map callback in /var/www/clients/client0/web29/web/lib/Cake/Model/Datasource/DboSource.php on line 451 Warning: Fixture creation for "matches_teams" failed "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 ''0=home' at line 4" in /var/www/clients/client0/web29/web/lib/Cake/TestSuite/Fixture/CakeTestFixture.php on line 210

And below that another error:
Error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'c0tipmastertest.matches_teams' doesn't exist 

In my fixture I had:

class MatchesTeamFixture extends CakeTestFixture {
/**
 * Fields
 *
 * @var array
 */
public $fields = array(
'match_id' => array('type' => 'integer', 'null' => false, 'default' => null),
'team_id' => array('type' => 'integer', 'null' => false, 'default' => null),
'home_away' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 4, 'key' => 'index', 'comment' => '0=home;1=away'),
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'home_away' => array('column' => 'home_away', 'unique' => 0)
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM')
);  
 (...)
So I just accidentally tried removing some stuff and removing the semicolon from the comment attribute worked:
 class MatchesTeamFixture extends CakeTestFixture {
/**
 * Fields
 *
 * @var array
 */
public $fields = array(
'match_id' => array('type' => 'integer', 'null' => false, 'default' => null),
'team_id' => array('type' => 'integer', 'null' => false, 'default' => null),
'home_away' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 4, 'key' => 'index'),
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'home_away' => array('column' => 'home_away', 'unique' => 0)
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM')
);

So I guess CakePHP doesn't escape the comment values. 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: