On Monday, November 5, 2012 11:12:19 PM UTC-8, Snarke wrote:
>
> About 18 months ago, I needed to get Sequel to cough up a list of foreign 
> keys for a model. I did it by slapping on a PostgreSQL-specific extension: 
>
> module Sequel 
>         class Model 
>                 def self.foreign_keys 
>                         Hash[*DB["SELECT tc.constraint_name, 
> kcu.column_name 
>                                 FROM information_schema.table_constraints 
> AS tc JOIN information_schema.key_column_usage AS kcu using 
> (constraint_name) 
>                                 WHERE constraint_type = 'FOREIGN KEY' AND 
> tc.table_name='#{self.table_name}'"].collect{|row| 
>                                         [row[:column_name].to_sym, 
> row[:constraint_name]] 
>                                 }.flatten] 
>                 end 
>         end 
> end 
>
> There've been a lot of newer releases since I wrote that. Is there now a 
> built-in way to access foreign keys?


Database#foreign_key_list has been added and works on quite a few database 
types that Sequel supports, including PostgreSQL.

Thanks,
Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/Gv0Gz_7nwsMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to