My join table wasn't working correctly so I tried to fix it by changing the syntax in the migrations.
I have a building, organization, and OrganizationBuilding classes
The original was
class CreateOrganizationBuildings < ActiveRecord::Migration
def change
create_table :organization_buildings, id: :uuid do |t|
t.uuid :organization_id, index: true
t.uuid :building_id, index: true
t.boolean :active, default: true
t.timestamps
end
end
end
I tried to change it to
class CreateOrganizationBuildings < ActiveRecord::Migration
def change
create_table :organization_buildings, do |t|
t.belongs_to :organization, index: true
t.belongs_to :building, index: true
t.boolean :active, default: true
t.timestamps
end
end
end
I have three different organizations one of the organizations building association worked correctly before and the rest didn't now none of them are working correctly.
class OrganizationBuilding < ActiveRecord::Base
belongs_to :organization
belongs_to :building
validates :organization, presence: true
validates :building, presence: true
validates :building, uniqueness: { scope: :organization }
end
class OrganizationBuilding < ActiveRecord::Base
belongs_to :organization
belongs_to :building
validates :organization, presence: true
validates :building, presence: true
validates :building, uniqueness: { scope: :organization }
end
class Building < ActiveRecord::Base
include Cloneable, SoftDestruction
has_many :apartments
has_many :organization_buildings
has_many :organizations, through: :organization_buildings
has_many :meters, as: :audit_structure
has_one :audit_structure, as: :physical_structure
end
Is there a problem when a redo a join table migration that it doesn't associate the database correctly?