# Many-to-Many foreign key setup

**URL:** <https://www.ruby-forum.com/t/many-to-many-foreign-key-setup/122793>\
**Category:** Rails\
**Created:** [December 12, 2007, 7:04am UTC](https://www.ruby-forum.com/t/many-to-many-foreign-key-setup/122793 "2007-12-12T07:04:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [December 12, 2007, 7:04am UTC](https://www.ruby-forum.com/t/many-to-many-foreign-key-setup/122793/1 "2007-12-12T07:04:34Z")

</div>

I’m setting up a many-to-many as per  
[http://wiki.rubyonrails.org/rails/pages/ThroughAssociations](http://wiki.rubyonrails.org/rails/pages/ThroughAssociations)  
and just wanted to run this by others before going too far down this  
path:

C:\code\strawr\db\migrate\>  
C:\code\strawr\db\migrate\>  
C:\code\strawr\db\migrate\>svn info  
Path: .  
URL: [https://strawr.googlecode.com/svn/trunk/db/migrate](https://strawr.googlecode.com/svn/trunk/db/migrate)  
Repository Root: [https://strawr.googlecode.com/svn](https://strawr.googlecode.com/svn)  
Repository UUID: 37ac5c3a-a740-0410-be57-6ddc613217ac  
Revision: 55  
Node Kind: directory  
Schedule: normal  
Last Changed Author: hawat.thufir  
Last Changed Rev: 55  
Last Changed Date: 2007-12-11 18:59:18 -0800 (Tue, 11 Dec 2007)

C:\code\strawr\db\migrate\>  
C:\code\strawr\db\migrate\>dir  
Volume in drive C has no label.  
Volume Serial Number is 0491-510F

Directory of C:\code\strawr\db\migrate

12/11/2007 07:00 PM .  
12/11/2007 07:00 PM …  
12/11/2007 07:00 PM 198 001\_categories.rb  
12/11/2007 07:00 PM 184 002\_feeds.rb  
12/11/2007 07:00 PM 245 003\_category\_feeds.rb  
3 File(s) 627 bytes  
2 Dir(s) 29,724,401,664 bytes free

C:\code\strawr\db\migrate\>  
C:\code\strawr\db\migrate\>type 001\_categories.rb  
class Categories \< ActiveRecord::Migration  
def self.up  
create\_table :categories do |table|  
table.column :category, string  
end  
end

```
    def self.down
            drop_table :categories
    end

```

end  
C:\code\strawr\db\migrate\>  
C:\code\strawr\db\migrate\>type 002\_feeds.rb  
class Feeds \< ActiveRecord::Migration  
def self.up  
create\_table :feeds do |table|  
table.column :feed, :string  
end  
end

```
    def self.down
            drop_table :feeds
    end

```

end

C:\code\strawr\db\migrate\>  
C:\code\strawr\db\migrate\>type 003\_category\_feeds.rb  
class CategoryFeeds \< ActiveRecord::Migration  
def self.up  
create\_table :category\_feeds do |table|  
table.column :category\_id, :integer  
table.column :feed\_id, :integer  
end

def self.down  
drop\_table :category\_feeds  
end  
end

C:\code\strawr\db\migrate\>  
C:\code\strawr\db\migrate\>

thanks,

Thufir
