Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spatial column failed #172

Open
sid606 opened this issue Apr 30, 2021 · 3 comments
Open

Update spatial column failed #172

sid606 opened this issue Apr 30, 2021 · 3 comments

Comments

@sid606
Copy link

sid606 commented Apr 30, 2021

When I want to save new object with spatial column the create is good but when I want to update existing model it fail and it give the following error:
"SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field (SQL: update locations set point_lat_lng = -23.9878441 40.7484404, locations.updated_at = 2021-04-30 15:58:02 where id = 444).

As you can see this is the problem
point_lat_lng = -23.9878441 40.7484404 is not converted into spatial file,

And this is on insert:
insert into locations (point_lat_lng, updated_at, created_at) values (ST_GeomFromText(?, ?, 'axis-order=long-lat'), ?, ?) -
array (size=4)
0 => string 'POINT(13.4113999 52.5234051)' (length=28)
1 => int 4326
2 => string '2021-04-30 15:36:42' (length=19)

Any help or sugestion?

@Mathias-Ooms
Copy link

I got the same issue. Temporary made the worst fix by deleting and inserting the object again.

@moridianmess
Copy link

I believe this is because there is no performUpdate function in the SpatialTrait. In my environment I've taken a copy of SpatialTrait and I'm using that instead. I've added the following function just after performInsert and now my updates to points work:

protected function performUpdate(EloquentBuilder $query, array $options = [])
{
	foreach ($this->attributes as $key => $value) {
		if ($value instanceof GeometryInterface) {
			$this->geometries[$key] = $value; //Preserve the geometry objects prior to the update
			$this->attributes[$key] = new SpatialExpression($value);
		}
	}

	$update= parent::performUpdate($query, $options);

	foreach ($this->geometries as $key => $value) {
		$this->attributes[$key] = $value; //Retrieve the geometry objects so they can be used in the model
	}

	return $update; //Return the result of the parent update
}

@coogle
Copy link

coogle commented Sep 16, 2022

I can confirm that adding the performUpdate method does the trick.. can this be turned into a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants