activerecord model belongs_to and validates_associated duplicate validation

18 views
Skip to first unread message

sreid

unread,
Aug 25, 2011, 1:06:36 PM8/25/11
to Ruby on Rails: Talk
In one of my models I have these lines :

belongs_to :user, :validate => true
...
validates_associated :user

When I remove the 2nd one, my tests run noticeably faster. Is the
above causing validations to be run twice ?

sreid

unread,
Aug 25, 2011, 1:11:33 PM8/25/11
to Ruby on Rails: Talk
And if it is a duplication, are there any differences, and which
method is best ?

sreid

unread,
Aug 25, 2011, 1:33:07 PM8/25/11
to Ruby on Rails: Talk
Also, is there some reason why validates_associated does not throw an
exception on nil ?

Tim Shaffer

unread,
Aug 25, 2011, 1:53:29 PM8/25/11
to rubyonra...@googlegroups.com
That's just the way it's designed to work. If you want to make sure it's not null, you'll need to also use validates_presence_of or validates :presence => true
Reply all
Reply to author
Forward
0 new messages