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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue