diff --git a/CHANGELOG.md b/CHANGELOG.md index 1857581..7697dbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md). +## 4.0.2 (25. November 2021) + ++ Fix issue when `timestamp_create` is provided by admin UI the value is is not accpeted as its overwritten by the TimestampBehavior. + ## 4.0.1 (3. August 2021) + [#25](https://github.com/luyadev/luya-module-news/pull/25) Fixed issue when using the Article Model in Queue Context. diff --git a/src/models/Article.php b/src/models/Article.php index d0e1533..55ddf63 100644 --- a/src/models/Article.php +++ b/src/models/Article.php @@ -75,12 +75,23 @@ public function behaviors() ], [ 'class' => TimestampBehavior::class, - 'createdAtAttribute' => 'timestamp_create', + 'createdAtAttribute' => false, 'updatedAtAttribute' => 'timestamp_update' ] ]; } + public function init() + { + parent::init(); + + $this->on(self::EVENT_BEFORE_INSERT, function() { + if (empty($this->timestamp_create)) { + $this->timestamp_create = time(); + } + }); + } + /** * @inheritdoc */