Fogbugz #54: add contacts_id to emails and phones tables.

This commit is contained in:
gchq 2011-05-18 00:34:00 +02:00
parent b1fbec0482
commit 73601a4da2
4 changed files with 107 additions and 61 deletions

View file

@ -8,7 +8,10 @@
<strong><%= c.lastname %></strong> <strong><%= c.lastname %></strong>
</div> </div>
<div class="twocol"> <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>
<div class="onecol"> <div class="onecol">
<%= c.street + " " + c.housenr %> <%= c.street + " " + c.housenr %>
@ -16,8 +19,7 @@
<%= c.plz + " " + c.place + ", " + c.country %> <%= c.plz + " " + c.place + ", " + c.country %>
</div> </div>
<div class="fourcol"> <div class="fourcol">
<small>Home</small> 0721 123 43 43 43<br /> have: <%= c.phones.count %> phones.
<small>Mobil</small> 0176 123 43 43 43
</div> </div>
</div> </div>
<% end %> <% end %>

View 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

View 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

View file

@ -1,58 +1,64 @@
# This file is auto-generated from the current state of the database. Instead # 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 # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.
# #
# Note that this schema.rb definition is the authoritative source for your # Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another # 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 # 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 # 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). # 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. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110515190518) do ActiveRecord::Schema.define(:version => 20110517221027) do
create_table "contacts", :force => true do |t| create_table "contacts", :force => true do |t|
t.string "firstname" t.string "firstname"
t.string "lastname" t.string "lastname"
t.string "street" t.string "street"
t.string "housenr" t.string "housenr"
t.string "plz" t.string "plz"
t.string "place" t.string "place"
t.string "country" t.string "country"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "emails", :force => true do |t| create_table "emails", :force => true do |t|
t.string "desc" t.string "desc"
t.string "address" t.string "address"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
end t.integer "contact_id"
end
create_table "phones", :force => true do |t|
t.string "desc" add_index "emails", ["contact_id"], :name => "fk_emails_contacts"
t.string "nr"
t.datetime "created_at" create_table "phones", :force => true do |t|
t.datetime "updated_at" t.string "desc"
end t.string "nr"
t.datetime "created_at"
create_table "users", :force => true do |t| t.datetime "updated_at"
t.string "email", :default => "", :null => false t.integer "contact_id"
t.string "encrypted_password", :limit => 128, :default => "", :null => false end
t.string "reset_password_token"
t.datetime "remember_created_at" add_index "phones", ["contact_id"], :name => "fk_phones_contacts"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at" create_table "users", :force => true do |t|
t.datetime "last_sign_in_at" t.string "email", :default => "", :null => false
t.string "current_sign_in_ip" t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "last_sign_in_ip" t.string "reset_password_token"
t.datetime "created_at" t.datetime "remember_created_at"
t.datetime "updated_at" t.integer "sign_in_count", :default => 0
end t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
add_index "users", ["email"], :name => "index_users_on_email", :unique => true t.string "current_sign_in_ip"
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true t.string "last_sign_in_ip"
t.datetime "created_at"
end 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