Skip to content

Commit

Permalink
Use :foreign_key name for belongs_to association if specified
Browse files Browse the repository at this point in the history
Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information
cjheath authored and justinfrench committed Aug 1, 2009
1 parent 954b086 commit 580d781
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/formtastic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ def create_boolean_collection(options)
# be used for the input
#
# belongs_to :author; f.input :author; will generate 'author_id'
# belongs_to :entity, :foreign_key = :owner_id; f.input :author; will generate 'owner_id'
# has_many :authors; f.input :authors; will generate 'author_ids'
# has_and_belongs_to_many will act like has_many
#
Expand All @@ -1098,7 +1099,7 @@ def generate_association_input_name(method)
if [:has_and_belongs_to_many, :has_many].include?(reflection.macro)
"#{method.to_s.singularize}_ids"
else
"#{method}_id"
reflection.options[:foreign_key] || "#{method}_id"
end
else
method
Expand Down

0 comments on commit 580d781

Please sign in to comment.