Skip to content

Commit

Permalink
Merge branch 'main' into allow-sthaving-to-use-st-expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ahawlitschek authored Jan 19, 2024
2 parents fe53a29 + 02b9eef commit dd5835b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed builder macro docblocks to use FQDN for an issue within laravel-ide-helper
- Fixed `ST_PROJECT` function not being migrated to the GeometryType enum.
- Fixed model attribute equality checks for geometries, reduces unnecessary database updates (thanks @adamczykpiotr)

## [1.4.0](https://github.com/clickbar/laravel-magellan/tree/1.4.0) - 2023-07-02

Expand Down
20 changes: 20 additions & 0 deletions src/Database/Eloquent/HasPostgisColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
use Clickbar\Magellan\IO\Generator\WKT\WKTGenerator;
use Clickbar\Magellan\IO\Parser\WKB\WKBParser;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;

/**
* @mixin Model
*/
trait HasPostgisColumns
{
public function getPostgisTypeAndSrid(string $key)
Expand Down Expand Up @@ -141,6 +145,22 @@ public function setRawAttributes(array $attributes, $sync = false)
return parent::setRawAttributes($attributes, $sync);
}

public function originalIsEquivalent($key)
{
$this->assertPostgisColumnsNotEmpty();

// Not a postgis column
if (array_key_exists($key, $this->postgisColumns) === false) {
return parent::originalIsEquivalent($key);
}

$attribute = Arr::get($this->attributes, $key);
$original = Arr::get($this->original, $key);

// Compare already cast objects
return $attribute == $original;
}

protected function assertPostgisColumnsNotEmpty()
{
if (! property_exists($this, 'postgisColumns')) {
Expand Down

0 comments on commit dd5835b

Please sign in to comment.