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?
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
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.