Skip to content

Commit

Permalink
Move profile from user to actor
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Jan 19, 2011
1 parent deba79c commit 0b0d1de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 4 additions & 0 deletions app/models/actor.rb
Expand Up @@ -13,6 +13,8 @@ class Actor < ActiveRecord::Base
:profile => '94x94' },
:default_url => "/images/:attachment/:style/:subtype_class.png"

has_one :profile, :dependent => :destroy

has_many :sent_ties,
:class_name => "Tie",
:foreign_key => 'sender_id',
Expand All @@ -33,6 +35,8 @@ class Actor < ActiveRecord::Base

after_create :initialize_ties

after_create :create_profile

class << self
# Get actor's id from an object, if possible
def normalize_id(a)
Expand Down
2 changes: 1 addition & 1 deletion app/models/profile.rb
@@ -1,3 +1,3 @@
class Profile < ActiveRecord::Base
belongs_to :user
belongs_to :actor
end
9 changes: 1 addition & 8 deletions app/models/user.rb
Expand Up @@ -3,11 +3,8 @@
class User < ActiveRecord::Base
devise *SocialStream.devise_modules

has_one :profile, :dependent => :destroy
accepts_nested_attributes_for :profile

# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :profile_attributes, :birthday
attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :profile_attributes

validates_presence_of :email

Expand All @@ -20,8 +17,6 @@ class User < ActiveRecord::Base
v.validates_length_of :password, :within => Devise.password_length, :allow_blank => true
end

after_create :create_profile

def age
return nil if profile.birthday.blank?
now = Time.now.utc.to_date
Expand Down Expand Up @@ -103,6 +98,4 @@ def find_or_initialize_with_error_by_email(value, error)
record
end
end


end
8 changes: 4 additions & 4 deletions lib/generators/social_stream/templates/migration.rb
Expand Up @@ -94,7 +94,7 @@ def self.up
add_index "posts", "activity_object_id"

create_table "profiles", :force => true do |t|
t.integer "user_id"
t.integer "actor_id"
t.date "birthday"
t.datetime "created_at"
t.datetime "updated_at"
Expand All @@ -115,7 +115,7 @@ def self.up
t.string "im", :limit => 45
end

add_index "profiles", "user_id"
add_index "profiles", "actor_id"

create_table "relation_permissions", :force => true do |t|
t.integer "relation_id"
Expand Down Expand Up @@ -213,7 +213,7 @@ def self.up

add_foreign_key "posts", "activity_objects", :name => "posts_on_activity_object_id"

add_foreign_key "profiles", "users", :name => "profiles_on_user_id"
add_foreign_key "profiles", "actors", :name => "profiles_on_actor_id"

add_foreign_key "relation_permissions", "relations", :name => "relation_permissions_on_relation_id"
add_foreign_key "relation_permissions", "permissions", :name => "relation_permissions_on_permission_id"
Expand Down Expand Up @@ -247,7 +247,7 @@ def self.down

remove_foreign_key "posts", :name => "posts_on_activity_object_id"

remove_foreign_key "profiles", :name => "profiles_on_user_id"
remove_foreign_key "profiles", :name => "profiles_on_actor_id"

remove_foreign_key "relation_permissions", :name => "relation_permissions_on_relation_id"
remove_foreign_key "relation_permissions", :name => "relation_permissions_on_permission_id"
Expand Down
3 changes: 3 additions & 0 deletions lib/social_stream/models/subject.rb
Expand Up @@ -25,6 +25,9 @@ module Subject
:home_wall, :profile_wall,
:to => :actor!

has_one :profile, :through => :actor

accepts_nested_attributes_for :profile

validates_presence_of :name

Expand Down

0 comments on commit 0b0d1de

Please sign in to comment.