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

1.0 maintenance: foreign_key instead of primary_key_name for Rails 3.1 #103

Open
wants to merge 1 commit into
base: 1.0-maintenance
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion lib/machinist/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def self.assigned_attributes_without_associations(lathe)
lathe.assigned_attributes.each_pair do |attribute, value|
association = lathe.object.class.reflect_on_association(attribute)
if association && association.macro == :belongs_to && !value.nil?
attributes[association.primary_key_name.to_sym] = value.id
if association.respond_to?(:foreign_key) # For Rails 3.1 and above
attributes[association.foreign_key.to_sym] = value.id
else
attributes[association.primary_key_name.to_sym] = value.id
end
else
attributes[attribute] = value
end
Expand Down