> I would think that in both db's you'd be best off by creating a view
> from the subquery and then modelling it with an AR class. You can then
> access your data from the view with the AR model as if it was a table,
> without having to resort to find_by_sql.
Yeah, but creating a model just for it is overkill IMO. And I don't
think either database supports updateable views (I don't know if MySQL
has views (or subqueries or union) now, as I haven't paid attention to
it for quite a while). Also, migrations don't work with views.
Naturally, views aren't updateable, but in PostgreSQL it is easily
achievable nonetheless. Simply create a rule that defines what to do
when an insert/delete/update operation is attempted on the view -
something like this:
CREATE RULE myview_insert AS ON INSERT TO myview DO INSTEAD
INSERT INTO mytable (id, name, phone)
VALUES (new.id, new.name, new.phone);