Skip to content

Commit

Permalink
added dependent destroy for globalize_translations. When a record wit…
Browse files Browse the repository at this point in the history
…h translated attributes is destroyed - the associated translations will be deleted as well. thanks to http://github.com/kares
  • Loading branch information
hukl committed Apr 29, 2009
1 parent ecfe0ba commit 0eef3b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/globalize/model/active_record/translated.rb
Expand Up @@ -25,7 +25,12 @@ def translates(*attr_names)
extend ClassMethods

self.globalize_proxy = Globalize::Model::ActiveRecord.create_proxy_class(self)
has_many :globalize_translations, :class_name => globalize_proxy.name, :extend => Extensions
has_many(
:globalize_translations,
:class_name => globalize_proxy.name,
:extend => Extensions,
:dependent => :delete_all
)

after_save :update_globalize_record
end
Expand Down
7 changes: 7 additions & 0 deletions test/model/active_record/translated_test.rb
Expand Up @@ -419,6 +419,13 @@ def tranlsations_included
assert p.reload(:readonly => true, :lock => true)
assert_raise(ArgumentError) { p.reload(:foo => :bar) }
end

test "dependent destroy of translation" do
p = Post.create :subject => "Foo", :content => "Bar"
assert_equal 1, PostTranslation.count
p.destroy
assert_equal 0, PostTranslation.count
end
end

# TODO should validate_presence_of take fallbacks into account? maybe we need
Expand Down

0 comments on commit 0eef3b8

Please sign in to comment.