Commit 55fbbbb6b391abb9e9989cb9ca8e72e77f1a2e5f

Authored by Rodrigo Souto
1 parent 3b316fad

[template-welcome-page] Add welcome_page relation to profiles

(ActionItem3075)
app/models/profile.rb
... ... @@ -138,6 +138,11 @@ class Profile < ActiveRecord::Base
138 138  
139 139 has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments
140 140  
  141 + # Although this should be a has_one relation, there are no non-silly names for
  142 + # a foreign key on article to reference the template to which it is
  143 + # welcome_page... =P
  144 + belongs_to :welcome_page, :class_name => 'Article', :dependent => :destroy
  145 +
141 146 def scraps(scrap=nil)
142 147 scrap = scrap.is_a?(Scrap) ? scrap.id : scrap
143 148 scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap)
... ...
db/migrate/20140409211533_add_welcome_page_id_to_profiles.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddWelcomePageIdToProfiles < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :profiles, :welcome_page_id, :integer
  4 + end
  5 +
  6 + def self.down
  7 + remove_column :profiles, :welcome_page_id
  8 + end
  9 +end
... ...
db/schema.rb
... ... @@ -484,6 +484,7 @@ ActiveRecord::Schema.define(:version =&gt; 20140605222753) do
484 484 t.integer "activities_count", :default => 0, :null => false
485 485 t.string "personal_website"
486 486 t.string "jabber_id"
  487 + t.integer "welcome_page_id"
487 488 end
488 489  
489 490 add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count"
... ...