Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix belongs_to reify for associations that use a different foreign_key #938

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
matchers to work with custom version association names
- [#929](https://github.com/airblade/paper_trail/pull/929) -
Fix error calling private method in rails 4.0
- [#938](https://github.com/airblade/paper_trail/pull/938) - Fix bug where
non-standard foreign key names broke belongs_to associations

## 6.0.2 (2016-12-13)

Expand Down
2 changes: 1 addition & 1 deletion lib/paper_trail/reifiers/belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module BelongsTo
class << self
# @api private
def reify(assoc, model, options, transaction_id)
id = model.send(assoc.association_foreign_key)
id = model.send(assoc.foreign_key)
version = load_version(assoc, id, transaction_id, options[:version_at])
record = load_record(assoc, id, options, version)
model.send("#{assoc.name}=".to_sym, record)
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Person < ActiveRecord::Base
has_many :authorships, foreign_key: :author_id, dependent: :destroy
has_many :books, through: :authorships
belongs_to :mentor, class_name: "Person", foreign_key: :mentor_id
has_paper_trail

# Convert strings to TimeZone objects when assigned
Expand Down
1 change: 1 addition & 0 deletions test/dummy/db/migrate/20110208155312_set_up_test_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def up
create_table :people, force: true do |t|
t.string :name
t.string :time_zone
t.integer :mentor_id
end

create_table :editorships, force: true do |t|
Expand Down
5 changes: 3 additions & 2 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@
end

create_table "people", force: :cascade do |t|
t.string "name"
t.string "time_zone"
t.string "name"
t.string "time_zone"
t.integer "mentor_id"
end

create_table "post_versions", force: :cascade do |t|
Expand Down