diff --git a/Gemfile b/Gemfile index efc42360b..d3fe4f902 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source 'http://rubygems.org' gem 'mysql2', '0.2.6' #gem 'pg' +#gem 'sqlite3' gem 'rails', '3.0.3' gem 'foreigner', '0.9.1' diff --git a/app/models/aspect_membership.rb b/app/models/aspect_membership.rb index 163dc6182..372e744ea 100644 --- a/app/models/aspect_membership.rb +++ b/app/models/aspect_membership.rb @@ -10,7 +10,7 @@ class AspectMembership < ActiveRecord::Base has_one :person, :through => :contact before_destroy do - if self.contact.aspects.size == 1 + if self.contact && self.contact.aspects.size == 1 self.user.disconnect(self.contact) end true diff --git a/app/models/notification.rb b/app/models/notification.rb index 7fceff2a8..167cad1a6 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -7,7 +7,7 @@ class Notification < ActiveRecord::Base include Diaspora::Socketable belongs_to :recipient, :class_name => 'User' - has_many :notification_actors + has_many :notification_actors, :dependent => :destroy has_many :actors, :class_name => 'Person', :through => :notification_actors, :source => :person belongs_to :target, :polymorphic => true diff --git a/app/models/person.rb b/app/models/person.rb index 0f93cd4c7..b59437b78 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -17,7 +17,7 @@ class Person < ActiveRecord::Base xml_attr :profile, :as => Profile xml_attr :exported_key - has_one :profile + has_one :profile, :dependent => :destroy delegate :last_name, :to => :profile before_validation :downcase_diaspora_handle @@ -25,8 +25,9 @@ class Person < ActiveRecord::Base diaspora_handle.downcase! unless diaspora_handle.blank? end - has_many :contacts #Other people's contacts for this person - has_many :posts, :foreign_key => :author_id #his own posts + has_many :contacts, :dependent => :destroy #Other people's contacts for this person + has_many :posts, :foreign_key => :author_id, :dependent => :destroy #his own posts + has_many :comments, :foreign_key => :author_id, :dependent => :destroy #his own comments belongs_to :owner, :class_name => 'User' diff --git a/app/models/post.rb b/app/models/post.rb index 72651977d..722c5a724 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -13,7 +13,7 @@ class Post < ActiveRecord::Base xml_attr :public xml_attr :created_at - has_many :comments, :order => 'created_at ASC' + has_many :comments, :order => 'created_at ASC', :dependent => :destroy has_many :likes, :conditions => {:positive => true}, :dependent => :delete_all has_many :dislikes, :conditions => {:positive => false}, :class_name => 'Like', :dependent => :delete_all diff --git a/app/models/user.rb b/app/models/user.rb index a0155bcbc..3d46d7a88 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -31,14 +31,14 @@ class User < ActiveRecord::Base has_one :person, :foreign_key => :owner_id delegate :public_key, :posts, :owns?, :diaspora_handle, :name, :public_url, :profile, :first_name, :last_name, :to => :person - has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id - has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id + has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id, :dependent => :destroy + has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id, :dependent => :destroy has_many :aspects has_many :aspect_memberships, :through => :aspects has_many :contacts has_many :contact_people, :through => :contacts, :source => :person - has_many :services - has_many :user_preferences + has_many :services, :dependent => :destroy + has_many :user_preferences, :dependent => :destroy before_save do person.save if person && person.changed?