Welcome Guest, Not a member yet? Register   Sign In
Saving/Loading queries: serializing/unserializing query parameters
#1

[eluser]djsc00p[/eluser]
Hi there,

Has anyone come across anything that allows you to save active record query parameters, so that they can be loaded later. The idea is to be able to serialize parameters, then later unserialize so that the query can be further manipulated with active record db class.

I thought about doing something like this, but I know it's somewhat involved considering that queries can get pretty long...

Any ideas or recommendations? I'm thinking about starting to write something adhoc, but I hope someone has dealt with this before.


Saving searches is one common feature that is frequently wanted in many projects. Being able to save these searches, load them back, and still manipulate them (ie. pagination, select fields, etc) would be ideal.
#2

[eluser]mddd[/eluser]
Usually you will have a method in a model somewhere to do the searching for you. Like
Code:
function find_hotels($country, $city, $options)
{
  ... do some db searching here ...
}
If that is the case couldn't you just save the terms you are searching for, instead of the actual query information from Active Record.
It is certainly possible but seems complicated to me. Building a new query through a method is not so much work. Working with the
internal information from Active Record won't give you much of a performance boost, especially as you will still be executing the
query again through the database so you're not really caching anything.
#3

[eluser]djsc00p[/eluser]
That's a good point. I think that's probably the right way of doing it.
One of my challenges was that some queries use different select fields or different joins; creating a generic method to re-construct this query (using saved options) will probably look really nasty.

Probably better than to save active record information though, I agree. Serializing last run query would be a cool feature to have though Smile

I guess reconstructing the query using options it is.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB