Currently using cake_1.2.0.7296-rc2 and postgres 8.2.5
I have a table that looks like this:
CREATE TABLE ranks
(
id serial NOT NULL,
code character varying(1) NOT NULL,
description character varying(15) NOT NULL,
CONSTRAINT ranks_pkey PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
ALTER TABLE ranks OWNER TO postgres;
When I ran "cake bake model ranks" and created a test fixture, I got
this as part of rank_fixture.php (in tests/fixtures/):
var $fields = array(
'id' => array('type'=>'integer', 'null' => false,
'default' =>
NULL, 'length' => 11, 'key' => 'primary'),
'code' => array('type'=>'string', 'null' => false,
'length' => 1),
'description' => array('type'=>'string', 'null' =>
false, 'length'
=> 15),
'indexes' => array('0' => array())
);
The 'indexes' part looked a bit suspicious but I ran the test anyway
at
http://forcetrak.dev/app/webroot/test.php?case=models%5Crank.test.php&app=true
and got this:
Error: Database table test_suite_ranks for model Rank was not found.
I looked further down and found this sql and error:
CREATE TABLE "test_suite_ranks" ( "id" serial NOT NULL, "code"
varchar(1) NOT NULL, "description" varchar(15) NOT NULL, PRIMARY KEY
());
ERROR: syntax error at or near ")" LINE 5: PRIMARY KEY ()); ^
I dug into the source code and found 2 suspect areas in the code. The
first was in cake/libs/model/datasources/dbo/dbo_postgres.php at line
635. Here it is with some context:
foreach ($indexes as $name => $value) {
if ($name == 'PRIMARY') {
$out = 'PRIMARY KEY (' .
$this->name($value['column']) . ')';
}
After doing some pr()'s, I discovered that when I ran the "cake bake
model rank" command line, $name's value was actually the number 0 and
the == comparison was running into the old "string typecasts to
integer 0" bug, and the if statement was evaluating to true. I
changed the "==" to "===". Bug #1 fixed.
I ran the command line again, however, and found I still had the same
problematic fixture code.
I dug into the fixture creation code and found this on line 908-913 in
cake/console/libs/tasks/model.php:
} else {
$col = "\t\t\t'indexes'
=> array(";
$props = array();
foreach ((array)$value
as $key => $index) {
$props[] =
"'{$key}' => array(".join(', ', $schema-
>__values($index)).")";
}
I did some a var_dump and found that $value was actually boolean false
when my problem occurred. The end result was that the (array)
coercion caused the $key to be 0 and the $index to be "".
So I modified that code to look like this:
} else {
$col = "\t\t\t'indexes'
=> array(";
if ($value != 0 and
$value != '') {
$props =
array();
foreach
((array)$value as $key => $index) {
$props[] = "'{$key}' => array(".join(', ', $schema-
>__values($index)).")";
}
$col .= join(',
', $props);
}
}
I then re-ran cake bake model and things looked better. The 'indexes'
array in the fixture was now empty. Bug #2 fixed.
I still feel that I've not dug deep enough, however, since I'm
confused why $value would be "false" when the console is processing
the schema output from dbo_postgres.php. It ought to be an empty
array, I think. And this doesn't even ask why the primary key index
isn't being detected.
I imagine I've got some deeper problem, but I have no idea what that
might be. Is no one else suffering these kinds of problems?
I checked the latest SVN trunk and all the code I've referred to here
is still there in the same form.
Anyway, I figured I'd post what I've got and let the Cake gods sort
out what I can't fathom. I look forward to seeing what's afoot.
jpt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---