Created
September 2, 2015 21:05
-
-
Save kylessnell/d90382b3b90266a38435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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