I'm overriding store method to add "created" and "created_by" column in database. modified column is getting inserted with current date properly. But, for a new request, created and created_by columns are not getting inserted with current date and current userid respectively.
I'm inserting a new row, hence this is new request. In that case, $this->id should should not be there. I tried to echo $this->id and it is indeed not set.
My code is:
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
$this->modified = $date->toSql();
if (isset($this->id))
{
// Existing item
$this->modified_by = $user->get('id');
}
else
{
// New Request. Set "created" column to current date and "created_by" to current userid
if (!(int) $this->created)
{
$this->created = $date->toSql();
}
if (empty($this->created_by))
{
$this->created_by = $user->get('id');
}
}
return parent::store($updateNulls);
}