Skip to content

Commit 56a9dc6

Browse files
authored
Merge pull request grimzy#129 from grimzy/issue-58-fix-retrieving-empty-geometry-collection-mysql-5.6
Fix issue where the WKB of empty GeometryCollections was not getting parsed (MySQL 5.6)
2 parents 5ff4b7f + 9e1bd59 commit 56a9dc6

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Eloquent/SpatialTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function setRawAttributes(array $attributes, $sync = false)
9595
$spatial_fields = $this->getSpatialFields();
9696

9797
foreach ($attributes as $attribute => &$value) {
98-
if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 15) {
98+
if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 13) {
9999
$value = Geometry::fromWKB($value);
100100
}
101101
}

tests/Integration/Models/GeometryModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ class GeometryModel extends Model
99

1010
protected $table = 'geometry';
1111

12-
protected $spatialFields = ['location', 'line'];
12+
protected $spatialFields = ['location', 'line', 'multi_geometries'];
1313
}

tests/Integration/SpatialTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ public function testInsertEmptyGeometryCollection()
184184
$geo->multi_geometries = new GeometryCollection([]);
185185
$geo->save();
186186
$this->assertDatabaseHas('geometry', ['id' => $geo->id]);
187+
188+
$geo2 = GeometryModel::find($geo->id);
189+
$this->assertNull($geo2->multi_geometries); // MySQL 5.6 saves null instead of empty GeometryCollection
187190
}
188191

189192
public function testUpdate()

0 commit comments

Comments
 (0)