class CreateMatches < ActiveRecord::Migration
def self.up
create_table :matches do |t|
t.integer :result_home
t.integer :result_away
t.references :clan, :as => :clan_home
t.references :clan, :as => :clan_away
t.references :league
t.timestamps
end
end
def self.down
drop_table :matches
end
end
I think code clears everything, I need to reference result_home to one clan and result_away to another. What is the best way to do so? I could create has_and_belongs_to_many but i think it's not good way in this case.
This looks like a join association call it
Match
, andThis is a little beyond my personal experience and I'm not 100% clear on the interpretation of the documentation for
:source
(check http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html). However, I think this will be along the right lines. YMMV.Comments and improvements are welcome!