views:

172

answers:

2

So I have a create_table like this for Courses at a School:

create_table :courses do |t|
  t.string :name
  t.references :course
  t.timestamps
end

but I want it to reference TWO other courses like:

has_many :transferrable_as #a Course

has_many :same_as #another Course

can I say

t.references :transferrable_as, :as=> :course

?

A: 

I don't think references accepts the :as option, but you can create your columns manually...

create_table :courses do |t| 
  t.string  :name 
  t.integer :course1_id
  t.integer :course2_id 
  t.timestamps 
end 
j.
+1  A: 

I think this thread has a different more Rails-ish way: http://stackoverflow.com/questions/417320/scaffolding-activerecord-two-columns-of-the-same-data-type

In the migration:

t.belongs_to :transferrable_as

t.belongs_to :same_as

marienbad