Skip to content

Instantly share code, notes, and snippets.

@synth
Created August 12, 2012 02:42
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 synth/3329212 to your computer and use it in GitHub Desktop.
Save synth/3329212 to your computer and use it in GitHub Desktop.
weird rails association behavior
$> rails new mynewapp
$> cd mynewapp
$> rails g model User
$> rails g model Whatever
$> rake db:migration
#user.rb
belongs_to :whatever
$> rails c
u = User.new
u.save
w = Whatever.new
w.save
u.whatever = w
u.save #no error!
u.whatever #=> w(Whatever)
u.reload #=> w(Whatever)
User.find(u.id).whatever #=> nil!!!!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment