Ruby/ActiveRecord/Primary key

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

if your primary key column is not named simply id, you can override this from within the class definition

=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.new
account.Name = "AAA"
account.save