delete the associated record from the database : Delete « ActiveRecord « Ruby






delete the associated record from the database


=begin

create database Contact;

use Contact;

CREATE TABLE Employee (
   Name VARCHAR(50),
   Phone VARCHAR(15)
);

=end

require "rubygems"
require "activerecord"

ActiveRecord::Base.establish_connection(
  :adapter => "mysql",
  :host => "localhost",
  :username => "root",
  :database => "Contact")

class Employee < ActiveRecord::Base
   set_table_name "employee"
   set_primary_key "Name"
end


account = Employee.find_by_Name("AAA")
puts account.destroy

 








Related examples in the same category

1.Delete a record with destroy
2.Account.destroy_all :artist => "Garth Brooks"
3.find_by_sql