Attempting to create a join table that takes two attributes on one model, and associates them with the id of a second model. Cannot use the id of the first model due to a constant refresh process, that reorders the rows on that model's table (ConstantlyRefreshingModels).
class ConstantlyRefreshingModels < ApplicationRecord
attr_accessor :home_id, :chair, :floor, :number
has_and_belongs_to_many :family
end
class Family < ApplicationRecord
attr_accessor :bread_winner
has_and_belongs_to_many :constantlyrefreshingmodel
end
class CreateFamilyModelThatConstantlyRefreshesJoinTable < ActiveRecord::Migration[5.0]
def change
create_join_table :families, :constantlyrefreshingmodel
end
end
Looking for a join table that looks like this:
home_id | number | family_id
-----------------------------
2 | '3003' | 4
1 | '2100' | 1
And then this works out for exposing data:
new_home = constantlyrefreshingmodel.where(home_id: 2)
new_home.families == 4 == true
Any suggestions as to creating the join table, and the declaring of the associations?