Currently, when I save, I try to check if the record falls into a specific area. This "scope" really is just some of the stored arguments for calling .where. In addition, with this βscopeβ I only check the values ββof the object, and not ever, as it relates to other objects in the database, so the database query will always be killed if that makes sense.
I could only come up with a solution below.
begin result = self.class.where(scope).find(self.id) rescue result = false end
The problem is that I have to query the database, even if I already have a record, and I have to run it not only before saving, but also after saving, to check the values ββthat it was and the values ββthat will be after saving because there is no way to query the database for the updated version if it has not been saved.
There may be some of these checks, so I would like to avoid having to do this twice, and also query the database many times, even if in the end I was just looking for something by id.
The only other solution I could think of is to have a method that somehow converts the where call to proc, which returns a boolean when the object is passed. The only problem with this is that the translation will somehow how to work with an active recording adapter, which is like an entire project on its own. So does anyone know some way to do this or a stone that will help?
PS I get the "region" from the cache, so I can not save it as proc, because you can not put procs in the cache using Rails.
rovermicrover
source share