rgeo/activerecord-postgis-adapter

RGeo Point apparent in AR model, but returns nil

Closed this issue · 2 comments

I'm not sure where this is coming from, but point-type column is returning nil when referenced. I can't get to the source of this issue. All the points are valid according ST_IsValid. Apologies if this is obvious.

Migration:

create_table :applicants do |t|
   t.st_point :location, srid: 4326
end

Creation:

def factory
    RGeo::Geographic.spherical_factory(:srid => 4326)
end

location = factory.point(row[0], row[1])
Applicant.create!({
    interests: [row[3],row[4],row[5]],
    prefers_nearby: row[6],
    has_transit_pass: row[7],
    location: location
 })

Interactive Ruby:

 => #<Position id: 1, location: #<RGeo::Geos::CAPIPointImpl:0x3fc1d1561ad0 "POINT (-71.06083441 42.35844033)">, created_at: "2016-02-24 18:52:11", updated_at: "2016-02-24 18:52:11">
2.1.5 :005 > Position.first.location
 => nil

But this works? I'm so confused:

2.1.5 :009 > f = Applicant.first
 => #<Applicant id: 1, location: #<RGeo::Geographic::SphericalPointImpl:0x3ff6664e9908 "POINT (-71.0857294 42.3000967)">>
2.1.5 :010 > f.location
 => nil
2.1.5 :012 > f[:location].geometry_type
 => RGeo::Feature::Point

... if you're using an abstract AR class, make sure you don't have a placeholder attribute by the same name.