Tag: ActiveRecord
book = Book.find(999)
book = Book.find_by_id(999) book = Book.find_by_name('おもしろい本') book = Book.find_by_name!('おもしろい本') #=>例外発生たい場合
book = Book.find_by(id: 999) book = Book.find_by(name: 'おもしろい本') book = Book.find_by!(name: 'おもしろい本') #=>例外発生させたい場合
book = Book.where("title=?", title).first
book = Book.where("title=? AND price=?" title, price).first
@product.save(validate: false)
item.new_record?
item.persisted?
class OldPerson < ActiveRecord::Base self.table_name = 'person' self.inheritance_column = :old_type self.establish_connection(:adapter=>"mysql2",:host=>"localhost",:username=>$dbuser,:password=>$dbpasswd,:data\ base=>$olddbname) end class Person < ActiveRecord::Base self.inheritance_column = :old_type self.establish_connection(:adapter=>"mysql2",:host=>"localhost",:username=>$dbuser,:password=>$dbpasswd,:data\ base=>$newdbname) end
class OldPerson < ActiveRecord::Base self.table_name = 'person' self.inheritance_column = :old_type end
innodb_buffer_pool_size = 512M innodb_log_file_size = 128M
require 'logger' ActiveRecord::Base.logger = Logger.new(STDOUT)
I18n.enforce_available_locales = false