Dmitry Sechin Fri May 20 09:49:53 -0400 2011

Subject: save to table/load from view

Hi!

I'm developing application which uses PosgreSQL/PostGIS to work with some spatial data.
PostGIS geometry type is a binary type, so I load spatial data with before_save callback wrapping my WKT (Well-Known-Text, e.g. "Point(1 2)") input in GeomFromText(...) (PostGIS internal function). The thing I can't do with single query - is to retrieve my data with geometry transformed back to WKT. I thought the possible solution would be to create view with query containing required transformation on PostGIS side, but how can I set up ActiveRecord to load from different table/view? Is it possible?


Yoan B Sun May 22 11:43:50 -0400 2011

I've got a branch to handle binary data like datetime.

https://github.com/greut/php-activerecord/compare/binary

Maybe geo stuff could me managed in a similar fashion? I'm not keen enough in Postgres/PostGIS to answer this question. I seems to be a very specific problem for a quite generic framework though.

Do you have any example of what you do and what you would like to achieve?

Dmitry Sechin Mon May 30 02:33:06 -0400 2011

Do you have a usage example for your Binary class?

I think my question is from another area: I need to some ActiveRecord\Model descendant to put data into one table & read data from another table (view actually). Is it possible to do such thing with some build/branch of php-activerecord?

Yoan B Mon May 30 02:45:05 -0400 2011

Regarding Binary, take a look at the tests.

Isn't the other thing simply replication master <-> slave? That should be done outside PHP I'd say:

  • http://dev.mysql.com/doc/refman/5.0/en/replication.html
  • http://www.enterprisedb.com/docs/en/9.0/pg/high-availability.html
  • http://freshmeat.net/projects/pgpool
Dmitry Sechin Mon May 30 03:19:50 -0400 2011

Well, maybe there's another solution other then the thing I proposed.
The simplest & straight-forward solution is to use custom save/load queries for model:

save (I'm actually save my data like this with before_save callback):
INSERT INTO .... all as usual .... VALUES)

load;
SELECT ... postgis_func2(geometry_field) FROM ...

but there's no before_load callback in php-activerecord, so I thought I may use custom view defined with

postgis_func2(geometry_field) as geometry_field

for load queries.

(1-4/4)