Skip to content

Commit

Permalink
fix(translations_relationship): conditions in the translations relati…
Browse files Browse the repository at this point in the history
…onship was dead
  • Loading branch information
paulRbr committed Apr 15, 2014
1 parent 5c6c652 commit 4f45acc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/translatable/active_record/macro.rb
Expand Up @@ -49,7 +49,7 @@ def translatable?
def setup_translatable!(options)
options[:table_name] ||= Translatable.translation_class.table_name
options[:foreign_key] ||= 'record_id'
options[:conditions] ||= ''
options[:conditions] ||= {}
options[:after_save] ||= false
options[:before_save] ||= false

Expand All @@ -66,14 +66,24 @@ def setup_translatable!(options)

has_many :translations, :class_name => translation_class.name,
:foreign_key => options[:foreign_key],
:conditions => options[:conditions],
:conditions => conditions(options),
:dependent => :destroy,
:extend => HasManyExtensions,
:autosave => false

after_create :save_translations!
after_update :save_translations!
end

def conditions(options)
table_name = self.table_name
proc {
c = options[:conditions]
c = self.instance_eval(&c) if c.is_a?(Proc)
c.merge(:scope => table_name, :locale => Translatable.locale)
}
end

end

module HasManyExtensions
Expand Down

0 comments on commit 4f45acc

Please sign in to comment.