Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-148

laravel-mongodb - Issue #2729: castAttribute does not handle nullable immutable date times

      TimothyBJacobs has created Issue #2729: castAttribute does not handle nullable immutable date times in laravel-mongodb. This Jira ticket was filed by alcaeus

      Issue Text:

      • Laravel-mongodb Version: 4.1.1
      • PHP Version: 8.1
      • Database Driver & Version: 6.0.13

      Description:

      The `castAttribute` method is overloaded in the base `Model` class. Unlike in the Core Laravel `hasAttributes` trait, it is missing handling for `null` values. See this code snippet from Laravel:

      ```php
      if (is_null($value) && in_array($castType, static::$primitiveCastTypes))

      { return $value; }

      ```

      Steps to reproduce

      ```php
      class MyModel extends \MongoDB\Laravel\Eloquent\Model

      { protected $casts = [ 'my_date' => 'immutable_datetime', ]; }

      $model = new MyModel();
      $model->my_date; // Should be null, instead is current time.
      ```

      Expected behaviour

      `null` should be returned.

      Actual behaviour

      The current time is returned.

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: