diff --git a/app/views/contacts/index.html.erb b/app/views/contacts/index.html.erb index 70e8d57..7e69d49 100644 --- a/app/views/contacts/index.html.erb +++ b/app/views/contacts/index.html.erb @@ -8,7 +8,10 @@ <%= c.lastname %>
- mail1 mail 2 mail 3 + have: <%= c.emails.count %> email. + <% c.emails.each do |e| %> + <%= ''%>e + <% end %>
<%= c.street + " " + c.housenr %> @@ -16,8 +19,7 @@ <%= c.plz + " " + c.place + ", " + c.country %>
- Home 0721 123 43 43 43
- Mobil 0176 123 43 43 43 + have: <%= c.phones.count %> phones.
<% end %> diff --git a/db/migrate/20110517220955_add_contact_id_to_phones.rb b/db/migrate/20110517220955_add_contact_id_to_phones.rb new file mode 100644 index 0000000..501d76b --- /dev/null +++ b/db/migrate/20110517220955_add_contact_id_to_phones.rb @@ -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 diff --git a/db/migrate/20110517221027_add_contact_id_to_emails.rb b/db/migrate/20110517221027_add_contact_id_to_emails.rb new file mode 100644 index 0000000..8ef2826 --- /dev/null +++ b/db/migrate/20110517221027_add_contact_id_to_emails.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 94d719b..35df10e 100644 --- a/db/schema.rb +++ b/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