Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

DataObject definition issue using numeric column names


Go to End


2 Posts   1164 Views

Avatar
wildflower1975

Community Member, 63 Posts

26 May 2016 at 2:57pm

I'm using a DataObject/table to store values per hour of a day so my column names are 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00

when I run sake dev/build my column names get changed to 01,02,03,04,05,06,07,08,09,10,11,12,13,1,2,3,4,5,6,7,8,9,00

I've tracked it down to Config::get() which is called in the DataObject::custom_database_fields() before the array_merge in DataObject::database_fields()

I'm not sure if it's a short coming in PHP array key syntax in that some are strings and others are integers, or if the Config class can be tweaked to handle this case.

as a work around I've added _ to my column names but this may cause issues later

custom_database_fields
array(27) {
["Date"]=>
string(11) "SS_Datetime"
["01"]=>
string(3) "Int"
["02"]=>
string(3) "Int"
["03"]=>
string(3) "Int"
["04"]=>
string(3) "Int"
["05"]=>
string(3) "Int"
["06"]=>
string(3) "Int"
["07"]=>
string(3) "Int"
["08"]=>
string(3) "Int"
["09"]=>
string(3) "Int"
[10]=>
string(3) "Int"
[11]=>
string(3) "Int"
[12]=>
string(3) "Int"
[13]=>
string(3) "Int"
[14]=>
string(3) "Int"
[15]=>
string(3) "Int"
[16]=>
string(3) "Int"
[17]=>
string(3) "Int"
[18]=>
string(3) "Int"
[19]=>
string(3) "Int"
[20]=>
string(3) "Int"
[21]=>
string(3) "Int"
[22]=>
string(3) "Int"
[23]=>
string(3) "Int"
["00"]=>
string(3) "Int"
["new"]=>
string(3) "Int"
["returned"]=>
string(3) "Int"
}

Avatar
martimiz

Forum Moderator, 1391 Posts

9 June 2016 at 12:08am

Edited: 09/06/2016 12:13am

This is Formost a php issue. From the manual:

"Strings containing valid integers will be cast to the integer type."

'00' to '09' aren't actually integers, but 10 to 23 are. Looks like the latter are turned into 0 to 13 on merge, which would be logical from a php point of view. And then the 0 value isn't turned into a field at all, which would account for one missing...

I don't really see any straightforward way to fix this...