Welcome, Guest. Please login or register.
Did you miss your activation email?
Feb. 08, 2012, 06:06:38 AM
55065 Posts in 12346 Topics by 65558 Members
Latest Member: gentle_dental
News:
 
The PRADO Community » Prado v3.x » General Discussion » Database » timestamp defaults to now() while AR sees it as NOT NULL « previous next »
Pages: [1] Print
Author Topic: timestamp defaults to now() while AR sees it as NOT NULL  (Read 1984 times)
acron
Senior Member
***

Karma: 8
Offline Offline

Posts: 76



View Profile
« on: Jul. 23, 2008, 07:55:56 PM »

I have a table of the following structure in my mysql-db:


CREATE TABLE contract (
  contract              SERIAL,
  user                  BIGINT UNSIGNED     NOT NULL,
  start                 DATE                NOT NULL,
  end                   DATE,
  description           VARCHAR(59),

  changed               TIMESTAMP           DEFAULT now()  ON UPDATE now(),

  PRIMARY KEY             (contract),

  FOREIGN KEY             (user) REFERENCES user (user)
    ON DELETE RESTRICT

)
ENGINE = INNODB;


If I try to save a new record with an AR like this:
Code:
$ad = new ActionDump;
$ad->start = $dbStart;
$ad->end = $dbEnd;
$ad->action_type = $this->action_type->getDropDownList()->getDropDownList()->getSelectedValue();
$ad->contract = $contract;

$ad->save();

I get the follwing error:

TActiveRecordException
Description

Property 'ActionDump::$changed' must not be null as defined by column 'changed' in table '`action_dump`'.

So the question is: What's going wrong there? How can that issue be fixed?

Greetings acron

ps I *can* insert a record without setting the changed column using the mysql console or phpmyadmin...
pps the Contract-AR is generated by php-cli and not modified.
Logged

“A little inaccuracy sometimes saves tons of explanation.” H. H. Munro
andiTaker
Junior Member
**

Karma: 0
Offline Offline

Posts: 28


View Profile
« Reply #1 on: Jul. 24, 2008, 11:26:19 AM »

you can try the following in your ActionDump class:

Code:
class ActionDump extends TActiveRecord {

const TABLE ="blabla"

public $changed = 0;

public static function finder($className=__CLASS__)
{
return parent::finder($className);
}

Logged
acron
Senior Member
***

Karma: 8
Offline Offline

Posts: 76



View Profile
« Reply #2 on: Jul. 24, 2008, 12:38:33 PM »

Thanks for your answer.
Explicit setting of a value which should be implictly be set by the default seems not a solution to me.

I consider the behaviour of AR as bugish and posted it with a possible solution here:
http://www.pradosoft.com/forum/index.php/topic,10603.0.html

Greets acron
Logged

“A little inaccuracy sometimes saves tons of explanation.” H. H. Munro
acron
Senior Member
***

Karma: 8
Offline Offline

Posts: 76



View Profile
« Reply #3 on: Jul. 24, 2008, 12:39:10 PM »

Thanks for your answer.
Explicit setting of a value which should be implictly set by a default value seems not a solution to me.

I consider the behaviour of AR as bugish and posted it with a possible solution here:
http://www.pradosoft.com/forum/index.php/topic,10603.0.html

Greets acron
Logged

“A little inaccuracy sometimes saves tons of explanation.” H. H. Munro
Pages: [1] Print 
« previous next »
Jump to: