Rails 3.1.0 server crashes when trying to delete Association model
I have the following models:
association.rb:
class Association < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :condominia, :dependent => :destroy
accepts_nested_attributes_for :condominia, :allow_destroy => true
end
condominium.rb
class Condominium < ActiveRecord::Base
belongs_to :association
has_many :owners, :dependent => :destroy
accepts_nested_attributes_for :owners, :a开发者_运维技巧llow_destroy => true
end
owner.rb
class Owner < ActiveRecord::Base
belongs_to :condominium
belongs_to :user
end
When I try to delete an Association model my rails server just crashes. Rails version 3.1.0 . And Ruby 1.9.2 p290 Any ideas why is this happening ?
Thanks.
UPDATE: If I try to remove the :dependent => :destroy it works. But because I need to create a batch of owners when a Condominium object is build I added:
def new_owners
return 0
end
def new_owners=(int_num)
int_num = int_num.to_i
if int_num > 0
int_num.times do
self.owners.create
end
end
end
The result is the same. Rails server crashing on save.
Without seeing the stack trace... beware of using names like Association.
In ActiveRecord there's already an Association class https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/association.rb
精彩评论