I'm in a need to use beforeFind(
) in a child class of CActiveRecord
.
Basically, I need to convert some data from before actual search in the DB is performed.
How do I alter the about-to-occur-find-operation that is about to take place, inside beforeFind()
? Messing with $this
attributes is not useful since its not even populated, which is a little surprise.
I've seen that the documentation mentions a "hidden CDbCriteria parameter" but I just couldn't guess how to use it... . Unfortunately, the documentation on this subject is slim.
What I need to do is rather simple: I've got a table column for storing IP addresses. The most efficient design from scalability perspective, is to use a VARBINARY(16) data type for the column. See for example this SO question page (and answers) on this.
So, the cleanest solution would be to have beforeFind()
, afterFind()
and beforeSave()
work transparently for the users.
In the code stack, the IP addresses would be the normal dotted-quad and in the DB level, its whatever that goes into the field after utilizing PHP's inet_pton()
method in those after/before hook methods.
It was supposed to be cool. and it is cool - with afterFind()
and beforeSave()
, where I have the ip_address attribute of the object at hand, at the mercy of my uber-manipulation powers.
Here's the point, and the need: thing is, I don't know how to achieve that on beforeFind()
. I cannot do a blind mergeWith()
as I need to check if ip_address attribute is part of the original criteria, and that I don't know how to do.
Help! TIA :)