From 45b0e31c895f9f752359116c497c65d44ec16cbc Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Tue, 23 Sep 2008 23:53:54 +0800 Subject: [PATCH] Add an ':association_options' option for passing additional options to the association creation methods. Signed-off-by: rick --- README | 1 + lib/technoweenie/attachment_fu.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README b/README index bbac4f5..f630c20 100644 --- a/README +++ b/README @@ -50,6 +50,7 @@ has_attachment(options = {}) :processor # Sets the image processor to use for resizing of the attached image. # Options include ImageScience, Rmagick, and MiniMagick. Default is whatever is installed. :uuid_primary_key # If your model's primary key is a 128-bit UUID in hexadecimal format, then set this to true. + :association_options # attachment_fu automatically defines associations with thumbnails with has_many and belongs_to. If there are any additional options that you want to pass to these methods, then specify them here. Examples: diff --git a/lib/technoweenie/attachment_fu.rb b/lib/technoweenie/attachment_fu.rb index a91dca9..a041c61 100644 --- a/lib/technoweenie/attachment_fu.rb +++ b/lib/technoweenie/attachment_fu.rb @@ -103,7 +103,11 @@ module Technoweenie # :nodoc: end attachment_options[:path_prefix] = attachment_options[:path_prefix][1..-1] if options[:path_prefix].first == '/' - with_options :foreign_key => 'parent_id' do |m| + association_options = { :foreign_key => 'parent_id' } + if attachment_options[:association_options] + association_options.merge!(attachment_options[:association_options]) + end + with_options(association_options) do |m| m.has_many :thumbnails, :class_name => "::#{attachment_options[:thumbnail_class]}" m.belongs_to :parent, :class_name => "::#{base_class}" unless options[:thumbnails].empty? end