I have an active record like so…
class Transaction extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'transaction';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
//ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'request', 'response', 'order_id'], 'required'],
[['amount'], 'number'],
[['user_id', 'order_id'], 'integer'],
[['created_at', 'transaction_number', 'reference_number', 'status'], 'safe'],
[['request', 'response'], 'string', 'max' => 2000],
[['comments'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'amount' => 'Amount',
'request' => 'Request',
'response' => 'Response',
'comments' => 'Comments',
'created_at' => 'Created At',
'transaction_number' => 'Transaction Number',
'status'=>'Status'
];
}...
As you can see, I wan’t a “created_at” behavior without the “updated_at” behavior. However, if I add one it forces me to add the other even though the updated_at behavior is not set. I get an error saying, Setting unknown property: common\models\ar\Transaction::updated_at.
I don’t understand why it is saying this because I removed the updated_at behavior. Am I not allowed to add one without the other?