Fogbugz #54: add contacts_id to emails and phones tables.
This commit is contained in:
parent
b1fbec0482
commit
73601a4da2
4 changed files with 107 additions and 61 deletions
|
|
@ -8,7 +8,10 @@
|
|||
<strong><%= c.lastname %></strong>
|
||||
</div>
|
||||
<div class="twocol">
|
||||
<a href="mailto:">mail1</a> <a href="mailto:">mail 2</a> <a href="mailto:">mail 3</a>
|
||||
have: <%= c.emails.count %> email.
|
||||
<% c.emails.each do |e| %>
|
||||
<%= '<a href="mailto:' + e + '">'%>e</a>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="onecol">
|
||||
<%= c.street + " " + c.housenr %>
|
||||
|
|
@ -16,8 +19,7 @@
|
|||
<%= c.plz + " " + c.place + ", " + c.country %>
|
||||
</div>
|
||||
<div class="fourcol">
|
||||
<small>Home</small> 0721 123 43 43 43<br />
|
||||
<small>Mobil</small> 0176 123 43 43 43
|
||||
have: <%= c.phones.count %> phones.
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
19
db/migrate/20110517220955_add_contact_id_to_phones.rb
Normal file
19
db/migrate/20110517220955_add_contact_id_to_phones.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class AddContactIdToPhones < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_table :phones do |t|
|
||||
t.references :contact
|
||||
end
|
||||
# add the foreign key
|
||||
execute <<-SQL
|
||||
ALTER TABLE phones
|
||||
ADD CONSTRAINT fk_phones_contacts
|
||||
FOREIGN KEY (contact_id)
|
||||
REFERENCES contacts(id)
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.down
|
||||
execute "ALTER TABLE phones DROP FOREIGN KEY fk_phones_contacts"
|
||||
remove_column :phones, :contact_id
|
||||
end
|
||||
end
|
||||
19
db/migrate/20110517221027_add_contact_id_to_emails.rb
Normal file
19
db/migrate/20110517221027_add_contact_id_to_emails.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class AddContactIdToEmails < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_table :emails do |t|
|
||||
t.references :contact
|
||||
end
|
||||
# add the foreign key
|
||||
execute <<-SQL
|
||||
ALTER TABLE emails
|
||||
ADD CONSTRAINT fk_emails_contacts
|
||||
FOREIGN KEY (contact_id)
|
||||
REFERENCES contacts(id)
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.down
|
||||
execute "ALTER TABLE emails DROP FOREIGN KEY fk_emails_contacts"
|
||||
remove_column :emails, :contact_id
|
||||
end
|
||||
end
|
||||
122
db/schema.rb
122
db/schema.rb
|
|
@ -1,58 +1,64 @@
|
|||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110515190518) do
|
||||
|
||||
create_table "contacts", :force => true do |t|
|
||||
t.string "firstname"
|
||||
t.string "lastname"
|
||||
t.string "street"
|
||||
t.string "housenr"
|
||||
t.string "plz"
|
||||
t.string "place"
|
||||
t.string "country"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "emails", :force => true do |t|
|
||||
t.string "desc"
|
||||
t.string "address"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "phones", :force => true do |t|
|
||||
t.string "desc"
|
||||
t.string "nr"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", :default => 0
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
||||
|
||||
end
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110517221027) do
|
||||
|
||||
create_table "contacts", :force => true do |t|
|
||||
t.string "firstname"
|
||||
t.string "lastname"
|
||||
t.string "street"
|
||||
t.string "housenr"
|
||||
t.string "plz"
|
||||
t.string "place"
|
||||
t.string "country"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "emails", :force => true do |t|
|
||||
t.string "desc"
|
||||
t.string "address"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "contact_id"
|
||||
end
|
||||
|
||||
add_index "emails", ["contact_id"], :name => "fk_emails_contacts"
|
||||
|
||||
create_table "phones", :force => true do |t|
|
||||
t.string "desc"
|
||||
t.string "nr"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "contact_id"
|
||||
end
|
||||
|
||||
add_index "phones", ["contact_id"], :name => "fk_phones_contacts"
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", :default => 0
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue