Skip to content

Commit

Permalink
[dm-constraints] renaming :nullify to :set_nil
Browse files Browse the repository at this point in the history
Signed-off-by: Balint Erdi <balint.erdi@gmail.com>
  • Loading branch information
balinterdi authored and Dan Kubb committed Jan 15, 2009
1 parent ed770e1 commit afed67b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dm-constraints/lib/dm-constraints.rb
Expand Up @@ -54,7 +54,7 @@ def initialize(name, repository_name, child_model, parent_model, options = {})

module DataMapper
module Associations
DELETE_CONSTRAINT_OPTIONS = [:protect, :destroy, :destroy!, :nullify, :skip]
DELETE_CONSTRAINT_OPTIONS = [:protect, :destroy, :destroy!, :set_nil, :skip]
def has(cardinality, name, options = {})

# NOTE: the reason for this fix is that with the ability to pass in two
Expand Down
4 changes: 1 addition & 3 deletions dm-constraints/lib/dm-constraints/data_objects_adapter.rb
Expand Up @@ -19,7 +19,7 @@ def create_constraints_statements(repository_name, model)
"NO ACTION"
when :destroy, :destroy!
"CASCADE"
when :nullify
when :set_nil
"SET NULL"
when :skip
nil
Expand All @@ -40,8 +40,6 @@ def destroy_constraints_statements(repository_name, model)

private

#TODO: ON (DELETE|UPDATE) CASCADE must be given for the 'destroy' case
# ON (DELETE|UPDATE) SET NULL must be given for the 'nullify' case
def create_constraints_statement(table_name, constraint_name, keys, foreign_table, foreign_keys, delete_constraint_type)
<<-EOS.compress_lines
ALTER TABLE #{quote_table_name(table_name)}
Expand Down
2 changes: 1 addition & 1 deletion dm-constraints/lib/dm-constraints/delete_constraint.rb
Expand Up @@ -12,7 +12,7 @@ def check_delete_constraints
if children && children.respond_to?(:each)
children.each { |child| child.destroy }
end
when :nullify
when :set_nil
if children && children.respond_to?(:each)
children.each do |child|
child.class.many_to_one_relationships.each do |mto_rel|
Expand Down
6 changes: 3 additions & 3 deletions dm-constraints/spec/integration/constraints_spec.rb
Expand Up @@ -71,7 +71,7 @@ class Cow
# :protect | raises exception if there are child records
# :destroy | deletes children
# :destroy! | deletes children directly without instantiating the resource, bypassing any hooks
# :nullify | sets parent id to nil in child associations
# :set_nil | sets parent id to nil in child associations
# :skip | does not do anything with children (they'll become orphan records)

describe "constraint options" do
Expand Down Expand Up @@ -157,10 +157,10 @@ class Cow

end

describe "when :constraint => :nullify is given" do
describe "when :constraint => :set_nil is given" do
before do
class Farmer
has n, :cows, :constraint => :nullify
has n, :cows, :constraint => :set_nil
end
class Cow
belongs_to :farmer
Expand Down

0 comments on commit afed67b

Please sign in to comment.