Customization of ActiveRecord models

I’m trying to determine how/if I can use MySql’s spatial extensions
with ActiveRecord. The spatial extensions usually require inserts in
the following format:

INSERT INTO locations (name, point) VALUES (“location
name”,GeomFromText('POINT( '));

And reads as

SELECT name, AsText(point) AS point FROM locations;

While I understand there’s methods to issue custom finder commands, I
don’t recall seeing anything about custom inserts/updates.

Does anyone have any recommendations on how I might handle a situation
like this?

Thanks in advance.

Noah

This plugin I made allows you to set AR model attributes to “db
functions”

http://www.agilewebdevelopment.com/plugins/activerecord_database_functions

User.new
user.password = ActiveRecord::Base::DBFunction.new( :password, ‘secret’ )

user.save
user.password
=> “428567f408994404”

class User < ActiveRecord::Base
def password=( pass )
write_attribute :password, DBFunction( :password, pass )
end
end
user = User.new
user.password = ‘secret’
user.save
user.password
=> “428567f408994404”

or for you…

locations.point = ActiveRecord::Base::DBFunction.new( :GeomFromText,
ActiveRecord::Base::DBFunction( :POINT, lat, lng ) )

Let me know if that helps!

mark