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

Joined select returns CAPIPointImpl instead of SphericalPointImpl #210

Closed
lessless opened this issue Feb 8, 2016 · 2 comments
Closed

Joined select returns CAPIPointImpl instead of SphericalPointImpl #210

lessless opened this issue Feb 8, 2016 · 2 comments

Comments

@lessless
Copy link

lessless commented Feb 8, 2016

Hello,

here are two queries, both of which are intended to select coordinates, but one returns SphericalPointImpl and other CAPIPointImpl.

rb(main):018:0> Address.select('coordinates::geometry').first.coordinates
  Address Load (1.3ms)  SELECT  coordinates::geometry FROM "addresses"  ORDER BY "addresses"."id" ASC LIMIT 1
=> #<RGeo::Geographic::SphericalPointImpl:0x3fe3d3af1d64 "POINT (106.0 10.0)">

rb(main):017:0> Realty.joins(:address).select('realties.id, addresses.coordinates::geometry').first.coordinates
  Realty Load (2.4ms)  SELECT  realties.id, addresses.coordinates::geometry FROM "realties" INNER JOIN "addresses" ON "addresses"."addressable_id" = "realties"."id" AND "addresses"."addressable_type" = $1  ORDER BY "realties"."id" ASC LIMIT 1  [["addressable_type", "Realty"]]
=> #<RGeo::Geos::CAPIPointImpl:0x3fe3d486985c "POINT (106.0 10.0)">

Might it be a bug?

@lessless lessless changed the title Joined select returns instead of SphericalPointImpl Joined select returns CAPIPointImpl instead of SphericalPointImpl Feb 8, 2016
@keithdoggett keithdoggett added this to High priority in Prioritized Issues Dec 5, 2020
@keithdoggett keithdoggett mentioned this issue Feb 11, 2021
3 tasks
@keithdoggett
Copy link
Member

This has been partially fixed by #334. In order to properly cast a geometry from a join, an attribute must be registered on the target table. In this example, you would have to do this.

class Realty < ActiveRecord::Base
  # ...
  attribute :coordinates, :st_point, srid: 4326, geographic: true
  # ...
end

and then the coordinates field from a join will be typecast to a geographic point.

@keithdoggett
Copy link
Member

Closing in favor of #336 since that is more explicit about the issue.

Prioritized Issues automation moved this from High priority to Closed Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants