Skip to content

Commit

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

Fix issue where the WKB of empty GeometryCollections was not getting parsed
  • Loading branch information
grimzy authored Mar 9, 2020
2 parents e5e4c89 + 8818d7a commit 7f62564
Show file tree
Hide file tree
Showing 3 changed files with 6 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 @@ -104,7 +104,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'];
}
4 changes: 4 additions & 0 deletions tests/Integration/SpatialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ public function testInsertEmptyGeometryCollection()
$geo->multi_geometries = new GeometryCollection([]);
$geo->save();
$this->assertDatabaseHas('geometry', ['id' => $geo->id]);

$geo2 = GeometryModel::find($geo->id);
$this->assertInstanceOf(GeometryCollection::class, $geo2->multi_geometries);
$this->assertEquals(0, count($geo2->multi_geometries));
}

public function testUpdate()
Expand Down

0 comments on commit 7f62564

Please sign in to comment.