Skip to content

Instantly share code, notes, and snippets.

@kylessnell
Created September 2, 2015 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylessnell/d90382b3b90266a38435 to your computer and use it in GitHub Desktop.
Save kylessnell/d90382b3b90266a38435 to your computer and use it in GitHub Desktop.
class Foo
include Mongoid::Document
include Mongoid::Timestamps
has_many :bars
has_many :bazs
before_validation do
puts "FOO VALIDATION"
end
end
class Bar
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :foo
before_validation do
puts "BAR VALIDATION"
end
end
class Baz
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :foo
before_validation do
puts "BAZ VALIDATION"
end
end
$> rails c
> foo = Foo.create
> bar = Bar.new(:foo => foo)
> bar.save
> baz = Baz.new(:foo => foo)
> baz.save
> foo.save
FOO VALIDATION
BAR VALIDATION
BAZ VALIDATION
=> true
> foo.reload && foo.save
FOO VALIDATION
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment