CodeIgniter Forums
Datamapper ORM - Deep Relationship with AES_encrypted fields in mySQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Datamapper ORM - Deep Relationship with AES_encrypted fields in mySQL (/thread-48002.html)



Datamapper ORM - Deep Relationship with AES_encrypted fields in mySQL - El Forum - 12-31-2011

[eluser]Unknown[/eluser]
Hi All,

If I've got the following setup...

Users (aes encrypted fields)
Documents
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.

Code:
$document = new Document;
$document->get_by_id($id);
        
$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.
Code:
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.

Thanks,

Jason