Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

when validating a record, if a validation context is used, use the same context when validating related records #4490

Merged
merged 1 commit into from Jan 17, 2012

Conversation

Projects
None yet
3 participants

E.G.:

class Parent < ActiveRecord::Base
  has_one :child
  validates_presence_of :name, :on => "custom_context"
  validates_associated :child
end

class Child < ActiveRecord::Base
  belongs_to :parent
  validates_presence_of :name, :on => "custom_context"
end

p = Parent.new(:name => "Montoto", :child => Child.new)
p.valid?(:custom_context) # => Returns true, even though the child is not valid under the same context.
validate related records in the same validation context as parent.
E.G.:

```ruby
class Parent < ActiveRecord::Base
  has_one :child
  validates_presence_of :name, :on => "custom_context"
  validates_associated :child
end

class Child < ActiveRecord::Base
  belongs_to :parent
  validates_presence_of :name, :on => "custom_context"
end

p = Parent.new(:name => "Montoto", :child => Child.new)
p.valid?(:custom_context) # => Returns true, even though the child is not valid under the same context.
```

josevalim added a commit that referenced this pull request Jan 17, 2012

Merge pull request #4490 from EmmanuelOga/master
when validating a record, if a validation context is used, use the same context when validating related records

@josevalim josevalim merged commit 5f8274e into rails:master Jan 17, 2012

@josevalim josevalim merged commit 9b15e01 into rails:master Jan 17, 2012

Contributor

masterkain commented on 9b15e01 Jan 17, 2012

Nice, this opens up interesting scenarios

josevalim added a commit that referenced this pull request Jun 3, 2013

Revert "Merge pull request #4490 from EmmanuelOga/master"
This behaviour doesn't actually make sense, the context of
the child should not be affected by the parent. See #10492.

This reverts commit 5f8274e, reversing
changes made to 81e837e.

josevalim added a commit that referenced this pull request Jun 3, 2013

Revert "Merge pull request #4490 from EmmanuelOga/master"
This behaviour doesn't actually make sense, the context of
the child should not be affected by the parent. See #10492.

This reverts commit 5f8274e, reversing
changes made to 81e837e.

rafaelfranca added a commit that referenced this pull request Jun 3, 2013

Revert "Merge pull request #4490 from EmmanuelOga/master"
This behaviour doesn't actually make sense, the context of
the child should not be affected by the parent. See #10492.

This reverts commit 5f8274e, reversing
changes made to 81e837e.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment