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>
</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 %>

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

@ -10,7 +10,7 @@
#
# 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|
t.string "firstname"
@ -29,15 +29,21 @@ ActiveRecord::Schema.define(:version => 20110515190518) do
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