CodeIgniter Forums

Full Version: Datamapper ORM - Deep Relationship with AES_encrypted fields in mySQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi All,

If I've got the following setup...

Users (aes encrypted fields)
Document Revisions

A Document can have many Document Revisions
A Document Revision has one user that uploaded it (stored as user_id)

I need to encrypt the fields in the users table using aes_encrypt and decode them using aes_decrypt via mySQL. Which works fine for the user model as I can add in the select query to do the decode functions.

But what if I want to return the deep relationship, from the Document object, and decrypt the users firstname, lastname and emailaddress fields.

$document = new Document;
$revisions = $document->document_revision->order_by('revision_number','desc')->get();

I'm currently doing the above, and then doing a foreach in the view... (I've removed the HTML inbetween the PHP tags for this demo.
foreach ($revisions as $k=>$revision){
                    <?Php echo $revision->revision_number;?>              
                    <?php echo $revision->notes;?>
                    <?php echo date('H:ia jS F Y',strtotime($revision->created));?>
                    <?php echo $revision->user->firstname." ".$revision->user->lastname;?>

So how do I get my user->firstname response to produce the decrypted aes field instead of the raw string from the DB which is a bunch of characters.