default values from DB definition

Login or register to post comments
3 replies [Last post]
Offline
Joined: 07/19/2009

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

Offline
Joined: 03/31/2008

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 . ")";
%>;
<% } %>
}

Offline
Joined: 07/09/2009

Thanks, Vexed!

This is handy code.

Offline
Joined: 07/19/2009

thanks, this is great!
I have opened ticket 317