From 55fbbbb6b391abb9e9989cb9ca8e72e77f1a2e5f Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 9 Apr 2014 21:54:41 +0000 Subject: [PATCH] [template-welcome-page] Add welcome_page relation to profiles --- app/models/profile.rb | 5 +++++ db/migrate/20140409211533_add_welcome_page_id_to_profiles.rb | 9 +++++++++ db/schema.rb | 1 + 3 files changed, 15 insertions(+), 0 deletions(-) create mode 100644 db/migrate/20140409211533_add_welcome_page_id_to_profiles.rb diff --git a/app/models/profile.rb b/app/models/profile.rb index 1506d8d..764b36c 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -138,6 +138,11 @@ class Profile < ActiveRecord::Base has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments + # Although this should be a has_one relation, there are no non-silly names for + # a foreign key on article to reference the template to which it is + # welcome_page... =P + belongs_to :welcome_page, :class_name => 'Article', :dependent => :destroy + def scraps(scrap=nil) scrap = scrap.is_a?(Scrap) ? scrap.id : scrap scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) diff --git a/db/migrate/20140409211533_add_welcome_page_id_to_profiles.rb b/db/migrate/20140409211533_add_welcome_page_id_to_profiles.rb new file mode 100644 index 0000000..eaa6370 --- /dev/null +++ b/db/migrate/20140409211533_add_welcome_page_id_to_profiles.rb @@ -0,0 +1,9 @@ +class AddWelcomePageIdToProfiles < ActiveRecord::Migration + def self.up + add_column :profiles, :welcome_page_id, :integer + end + + def self.down + remove_column :profiles, :welcome_page_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 15598d2..378bb5a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -484,6 +484,7 @@ ActiveRecord::Schema.define(:version => 20140605222753) do t.integer "activities_count", :default => 0, :null => false t.string "personal_website" t.string "jabber_id" + t.integer "welcome_page_id" end add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" -- libgit2 0.21.2