Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Model.foreign_keys
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dave Howell  
View profile  
 More options Nov 6 2012, 2:12 am
From: Dave Howell <groups.20...@grandfenwick.net>
Date: Mon, 5 Nov 2012 23:12:16 -0800
Local: Tues, Nov 6 2012 2:12 am
Subject: Model.foreign_keys
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Nov 6 2012, 11:31 am
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Tue, 6 Nov 2012 08:31:37 -0800 (PST)
Local: Tues, Nov 6 2012 11:31 am
Subject: Re: Model.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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »