Hey,

On Mon, 2011-02-07 at 15:22 +0100, Xavier Noria wrote:
> On Mon, Feb 7, 2011 at 2:28 PM, Rainer Frey <[email protected]> wrote:
> 
> > But this thread seems to suggest one should simply validate the
> > association attribute instead. Is that not sufficient then?
> 
> You can't still be sure the association is valid, because the
> associated object is cached if previously fetched, and the FK can be
> changed directly:

This does work 'properly' on edge, due to the stale-checking mechanism.
I just tried it. Voila:

$ rails c
Loading development environment (Rails 3.1.0.beta)
ruby-1.9.2-p136 :001 > post = Post.create
 => #<Post id: 1> 
ruby-1.9.2-p136 :002 > comment = post.comments.create
 => #<Comment id: 1, post_id: 1> 
ruby-1.9.2-p136 :003 > comment.post_id = -1
 => -1 
ruby-1.9.2-p136 :004 > comment.save
 => false 
ruby-1.9.2-p136 :005 > comment.errors
 => {:post=>["can't be blank"]} 
ruby-1.9.2-p136 :006 > comment.post
 => nil 

Jon

-- 
http://jonathanleighton.com/

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to