The proper way to model this is to use a many-to-many join table and the corresponding has_many_through association type in Rails.
On Saturday, April 16, 2016, Ao Wu <[email protected]> wrote: > CREATE TABLE drivers ( > driver_id integer PRIMARY KEY, > first_name text, > last_name text, > ... > ); > > CREATE TABLE races ( > race_id integer PRIMARY KEY, > title text, > race_day DATE, > ... > drivers1 integer[]; > drivers2 integer[]; > drivers3 integer[]; > drivers4 integer[]; > drivers5 integer[]; > ); > > If have above tables, we have many `drivers` reference in `races` table. > > So we may can do this in Model: > > class Race < ActiveRecord::Base > has_many :drivers1, array_reference: :drivers > has_many :drivers2, array_reference: :drivers > has_many :drivers3, array_reference: :drivers > has_many :drivers4, array_reference: :drivers > has_many :drivers5, array_reference: :drivers > end > > class Driver < ActiveRecord::Base > belongs_to :race, array_reference: :drivers1, dependent: :destroy > belongs_to :race, array_reference: :drivers2, dependent: :destroy > belongs_to :race, array_reference: :drivers3, dependent: :destroy > belongs_to :race, array_reference: :drivers4, dependent: :destroy > belongs_to :race, array_reference: :drivers5, dependent: :destroy > end > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <javascript:_e(%7B%7D,'cvml','rubyonrails-core%[email protected]');> > . > To post to this group, send email to [email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');>. > Visit this group at https://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
