-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 7.5.4
-
Component/s: Docs
-
None
class TimeTable include Mongoid::Document belongs_to :account, class_name: 'Account', inverse_of: :time_tables belongs_to :company_account, class_name: 'Account', inverse_of: :company_time_table, optional: true end
class Account include Mongoid::Document has_one :company_time_table, class_name: 'TimeTable', inverse_of: :company_account, dependent: :destroy, validate: false has_many :time_tables, class_name: 'TimeTable', inverse_of: :account, dependent: :destroy, validate: false end
account = Account.create!
ex_time_table = TimeTable.create(account:, company_account: account)
new_time_table = TimeTable.create(account:)
account.company_time_table = new_time_table # this codes produce the deletion of the ex_time_table document
The dependent: :destroy from the company_time_table relation, produces the deletion of the object when is unassigned as company_time_table from the account.
This is completely unexpected, the dependent should only be affected when the account is destroyed.