Skip to content

Commit

Permalink
add reset association
Browse files Browse the repository at this point in the history
  • Loading branch information
Giallombardo Nathan committed May 28, 2024
1 parent cff1218 commit 9355151
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/couchbase-orm/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def belongs_to(name, **options)

instance_variable_set(instance_var, value)
end

define_method(:"#{name}_reset") do
remove_instance_variable(instance_var) if instance_variable_defined?(instance_var)
end
end

def has_and_belongs_to_many(name, **options)
Expand Down Expand Up @@ -106,6 +110,10 @@ def has_and_belongs_to_many(name, **options)
instance_variable_set(instance_var, value)
end

define_method(:"#{name}_reset") do
self.remove_instance_variable(instance_var) if self.instance_variable_defined?(instance_var)
end

return unless options[:autosave]

save_method = :"autosave_associated_records_for_#{name}"
Expand Down
4 changes: 4 additions & 0 deletions lib/couchbase-orm/utilities/has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class #{class_name} < CouchbaseOrm::Base
end
end

define_method(:"#{model}_reset") do
self.remove_instance_variable(instance_var) if self.instance_variable_defined?(instance_var)
end

@associations ||= []
@associations << [model, options[:dependent]]
end
Expand Down

0 comments on commit 9355151

Please sign in to comment.