Skip to content

Commit

Permalink
Merge pull request #129 from grimzy/issue-58-fix-retrieving-empty-geo…
Browse files Browse the repository at this point in the history
…metry-collection-mysql-5.6

Fix issue where the WKB of empty GeometryCollections was not getting parsed (MySQL 5.6)
  • Loading branch information
grimzy authored Mar 9, 2020
2 parents 5ff4b7f + 9e1bd59 commit 56a9dc6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Eloquent/SpatialTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function setRawAttributes(array $attributes, $sync = false)
$spatial_fields = $this->getSpatialFields();

foreach ($attributes as $attribute => &$value) {
if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 15) {
if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 13) {
$value = Geometry::fromWKB($value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Models/GeometryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class GeometryModel extends Model

protected $table = 'geometry';

protected $spatialFields = ['location', 'line'];
protected $spatialFields = ['location', 'line', 'multi_geometries'];
}
3 changes: 3 additions & 0 deletions tests/Integration/SpatialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public function testInsertEmptyGeometryCollection()
$geo->multi_geometries = new GeometryCollection([]);
$geo->save();
$this->assertDatabaseHas('geometry', ['id' => $geo->id]);

$geo2 = GeometryModel::find($geo->id);
$this->assertNull($geo2->multi_geometries); // MySQL 5.6 saves null instead of empty GeometryCollection
}

public function testUpdate()
Expand Down

0 comments on commit 56a9dc6

Please sign in to comment.