I have two tables that both have no primary key. below is the two tables structure.
How can I use this in a join table on column date in rails ?
Meanwhile, Date columns are not unique in both tables.
I have two tables that both have no primary key. below is the two tables structure.
How can I use this in a join table on column date in rails ?
Meanwhile, Date columns are not unique in both tables.
From my understanding (which may be wrong), you need to use a Primary key, in order to identify foreign keys in Rails
Foreign Keys
However, you could try using the association_foreign_key
and foreign_key
arguments in your associations definitions (only works for HABTM):
#app/models/table_a.rb
Class TableA < ActiveRecord::Base
has_and_belongs_to_many :table_b, foreign_key: "country_id", association_foreign_key: "hour"
end
#app/models/table_b.rb
Class TableA < ActiveRecord::Base
has_and_belongs_to_many :table_a, foreign_key: "hour", association_foreign_key: "country_id"
end
table_as_table_bs
hour | country_id
Would be so difficult to include an id
column in your tables??