On Monday, September 26, 2016 at 10:35:40 PM UTC-7, binarypaladin wrote:
>
> So, let's say I'm using pgcrypto and in some circumstances, if a user has 
> sufficient access, I want to decrypt a column in the select. This is simple 
> enough when selecting using a single table or model.
>
> So, let's say table1 has a column called crypted_column and I select 
> pgp_sym_decrypt(crypted_column, key) AS decrypted_column. Pretty simple. 
>
> class Table1
>   def decrypted_column
>     self[:decrypted_column]
>   end
> end
>
> So, t1 = 
> Table1.select_append(:pgp_sym_decrypt.sql_function(:crypted_column, 
> key).as(:decrypted_column)).first gives me t1.decrypted_column => 
> "decrypted value"
>
> However, how do I get this value to show up in an eager graph—preferably 
> without having to update every single instance of the association? 
>
> So let's say I have table2, table3, and table4 and they all have either a 
> many_to_one OR a one_through_one association with table1.
>
> If I do 
> Table2.eager_graph(:table1).select_append(:pgp_sym_decrypt.sql_function(:crypted_column,
>  
> key).as(:decrypted_column)).first I can SEE the correct key in the hash 
> with the decrypted value, but if I do .all (which gives me the models 
> rather than a hash of values) where does "decrypted_column" go, where is it 
> accessible from, and how do I tell the process, "Hey. decrypted_column goes 
> with table1?"
>

You should use add_graph_aliases to do this:

  ds.add_graph_aliases(:decrypted_column=>[:table1, 
:column1, :pgp_sym_decrypt.sql_function(:crypted_column, key)]) 

:table1 here is the table alias in which you want to place the data (which 
hash to place the data), and :column1 is the column alias to use (which 
hash key to use).

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to