use mysql function for ActiveRecord setter/getter methods

I have a project using: Ruby on Rails and MySQL.

I have a table with a GEOMETRY field Coordinates with the data type Point. I would like to set the value of this field with WKT "POINT(40 100)" but when ActiveRecord saves the field it should set the value to GeomFromText(WKT) and when reading from the column it should read AsText(GEOMETRY).

Is it possible to configure "SQL-modifiers" for the set and get methods of this field?

Thanks in advance

Upvotes: 1

Views: 195

Answers (1)

For other users having similar problems I have found a solution.

  • install gem activerecord-mysql2spatial-adapter
  • factory = RGeo::Cartesian.factory

    model.Coordinates = factory.point(longitude, latitude)

Cheers

Upvotes: 1

Related Questions