Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created August 4, 2011 14:19
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 jonleighton/1125257 to your computer and use it in GitHub Desktop.
Save jonleighton/1125257 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'logger'
puts "Active Record #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:user => 'root',
:database => 'test'
)
ActiveRecord::Schema.define do
create_table :comments, :force => true do |t|
t.integer :post_id
end
create_table :posts, :force => true do |t|
end
end
class Post < ActiveRecord::Base
end
class Comment < ActiveRecord::Base
belongs_to :post
end
ActiveRecord::Base.logger = Logger.new(STDOUT)
Comment.joins(:post).where('posts.id IS NOT NULL').update_all(:post_id => 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment