diff --git a/gemfiles/Gemfile.6.1.mysql.lock b/gemfiles/Gemfile.6.1.mysql.lock index 0b6106a..8f28c11 100644 --- a/gemfiles/Gemfile.6.1.mysql.lock +++ b/gemfiles/Gemfile.6.1.mysql.lock @@ -1,8 +1,8 @@ PATH remote: .. specs: - temporal_tables (3.0.0) - rails (>= 6.0, < 7.2) + temporal_tables (3.0.1) + rails (>= 6.1, < 7.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.6.1.pg.lock b/gemfiles/Gemfile.6.1.pg.lock index 366786a..4a4593a 100644 --- a/gemfiles/Gemfile.6.1.pg.lock +++ b/gemfiles/Gemfile.6.1.pg.lock @@ -1,8 +1,8 @@ PATH remote: .. specs: - temporal_tables (3.0.0) - rails (>= 6.0, < 7.2) + temporal_tables (3.0.1) + rails (>= 6.1, < 7.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.7.0.mysql.lock b/gemfiles/Gemfile.7.0.mysql.lock index bddde12..06b63c1 100644 --- a/gemfiles/Gemfile.7.0.mysql.lock +++ b/gemfiles/Gemfile.7.0.mysql.lock @@ -1,8 +1,8 @@ PATH remote: .. specs: - temporal_tables (3.0.0) - rails (>= 6.0, < 7.2) + temporal_tables (3.0.1) + rails (>= 6.1, < 7.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.7.0.pg.lock b/gemfiles/Gemfile.7.0.pg.lock index 9652c3a..a028873 100644 --- a/gemfiles/Gemfile.7.0.pg.lock +++ b/gemfiles/Gemfile.7.0.pg.lock @@ -1,8 +1,8 @@ PATH remote: .. specs: - temporal_tables (3.0.0) - rails (>= 6.0, < 7.2) + temporal_tables (3.0.1) + rails (>= 6.1, < 7.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.7.1.mysql.lock b/gemfiles/Gemfile.7.1.mysql.lock index 7740ca1..f8c76f1 100644 --- a/gemfiles/Gemfile.7.1.mysql.lock +++ b/gemfiles/Gemfile.7.1.mysql.lock @@ -1,8 +1,8 @@ PATH remote: .. specs: - temporal_tables (3.0.0) - rails (>= 6.0, < 7.2) + temporal_tables (3.0.1) + rails (>= 6.1, < 7.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.7.1.pg.lock b/gemfiles/Gemfile.7.1.pg.lock index 8b8cb55..0b2506e 100644 --- a/gemfiles/Gemfile.7.1.pg.lock +++ b/gemfiles/Gemfile.7.1.pg.lock @@ -1,8 +1,8 @@ PATH remote: .. specs: - temporal_tables (3.0.0) - rails (>= 6.0, < 7.2) + temporal_tables (3.0.1) + rails (>= 6.1, < 7.2) GEM remote: https://rubygems.org/ diff --git a/lib/temporal_tables/temporal_class.rb b/lib/temporal_tables/temporal_class.rb index 0c7522e..cc7f49a 100644 --- a/lib/temporal_tables/temporal_class.rb +++ b/lib/temporal_tables/temporal_class.rb @@ -42,8 +42,7 @@ def self.temporalize_associations! # rubocop:disable Metrics/MethodLength, Metri association.macro, association.name, **association.options.merge( class_name: clazz.name, - foreign_key: association.foreign_key, - primary_key: clazz.orig_class.primary_key + foreign_key: association.foreign_key ) ) end diff --git a/lib/temporal_tables/version.rb b/lib/temporal_tables/version.rb index 4c8a7a6..cdee7f5 100644 --- a/lib/temporal_tables/version.rb +++ b/lib/temporal_tables/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module TemporalTables - VERSION = '3.0.0' + VERSION = '3.0.1' end diff --git a/spec/basic_history_spec.rb b/spec/basic_history_spec.rb index b323c0c..dcf4465 100644 --- a/spec/basic_history_spec.rb +++ b/spec/basic_history_spec.rb @@ -264,3 +264,19 @@ end end end + +describe Hamster do + context 'with tables that have non-default primary key names' do + let(:hamster) { Hamster.create name: 'Fluffy' } + let(:wheel) { HamsterWheel.create hamster: hamster } + + it 'can create instance of class with nested class name with history entries' do + expect(hamster).not_to be_nil + expect(wheel).not_to be_nil + expect(hamster.hamster_wheel).not_to be_nil + hamster_history = Hamster.history.at(Time.now.utc).first + expect(hamster_history).not_to be_nil + expect(hamster_history.hamster_wheel).not_to be_nil + end + end +end diff --git a/spec/internal/app/models/hamster.rb b/spec/internal/app/models/hamster.rb new file mode 100644 index 0000000..932ce8d --- /dev/null +++ b/spec/internal/app/models/hamster.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Hamster < ActiveRecord::Base + self.primary_key = :uuid + + has_one :hamster_wheel, foreign_key: :hamster_uuid, inverse_of: :hamster +end diff --git a/spec/internal/app/models/hamster_wheel.rb b/spec/internal/app/models/hamster_wheel.rb new file mode 100644 index 0000000..5f98e44 --- /dev/null +++ b/spec/internal/app/models/hamster_wheel.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class HamsterWheel < ActiveRecord::Base + belongs_to :hamster, foreign_key: :hamster_uuid, primary_key: :uuid, inverse_of: :hamster_wheel +end diff --git a/spec/internal/db/schema.rb b/spec/internal/db/schema.rb index 0e577ab..b77991f 100644 --- a/spec/internal/db/schema.rb +++ b/spec/internal/db/schema.rb @@ -69,4 +69,22 @@ t.belongs_to :bird, type: (postgres ? :uuid : :integer) t.integer :height end + + if postgres + create_table :hamsters, id: false do |t| + t.column :uuid, :uuid, default: 'gen_random_uuid()' + t.string :name + end + execute 'ALTER TABLE hamsters ADD PRIMARY KEY (uuid);' + add_temporal_table :hamsters + else + create_table :hamsters, primary_key: :uuid, temporal: true do |t| + t.string :name + end + end + + create_table :hamster_wheels, id: (postgres ? :uuid : :integer), temporal: true do |t| + t.column :hamster_uuid, (postgres ? :uuid : :bigint), null: false + t.foreign_key :hamsters, column: :hamster_uuid, primary_key: :uuid + end end