postgresql array foreign keys support

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

``

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.