default values from DB definition
Sun, 07/26/2009 - 17:41
dear all,
Qcubed gets the default values from the database definition, for example DeletedDefault has the default value for the field "Deleted".
I have noticed that this value is never user, is this expected?
Shouldn't we populate the classes with the default values from DB?
thanks

When I first proposed this for inclusion in QCodo, Mike Ho responded that it would be additional overhead that would be uneccessary for most projects. I'm not entirely sure I agree, but think leaving the choice up to the user is definately safe.
If you do want to initialize your classes, here's the code you need to add to /includes/qcodo/codegen/templates/db_orm/class_gen/_main.tpl:
public function __construct()
{
$this->Initialize();
}
public function Initialize()
{
<% foreach ($objTable->ColumnArray as $objColumn) { %>
$this-><%= $objColumn->VariableName %> = <%
$defaultVarName = $objTable->ClassName . '::' . $objColumn->PropertyName . 'Default';
if ($objColumn->VariableType != QType::DateTime)
return ($defaultVarName);
return "(" . $defaultVarName . " === null)?null:new QDateTime(" . $defaultVarName . ")";
%>;
<% } %>
}
Thanks, Vexed!
This is handy code.
thanks, this is great!
I have opened ticket 317