generates a unique constraint name given a table and a relationships
@param [String] storage_name
name of table to constrain
@param [String] relationship_name
name of the relationship to constrain
@return [String]
name of the constraint
@api private
# File lib/data_mapper/constraints/adapters/do_adapter.rb, line 186 186: def constraint_name(storage_name, relationship_name) 187: identifier = "#{storage_name}_#{relationship_name}"[0, self.class::IDENTIFIER_MAX_LENGTH - 3] 188: "#{identifier}_fk" 189: end
Generates the SQL statement to create a constraint
@param [String] constraint_name
name of the foreign key constraint
@param [String] constraint_type
type of constraint to ALTER source_storage_name with
@param [String] source_storage_name
name of table to ALTER with constraint
@param [Array(String)] source_keys
columns in source_storage_name that refer to foreign table
@param [String] target_storage_name
target table of the constraint
@param [Array(String)] target_keys
columns the target table that are referred to
@return [String]
SQL DDL Statement to create a constraint
@api private
# File lib/data_mapper/constraints/adapters/do_adapter.rb, line 144 144: def create_constraints_statement(constraint_name, constraint_type, source_storage_name, source_keys, target_storage_name, target_keys) 145: DataMapper::Ext::String.compress_lines( ALTER TABLE #{quote_name(source_storage_name)} ADD CONSTRAINT #{quote_name(constraint_name)} FOREIGN KEY (#{source_keys.join(', ')}) REFERENCES #{quote_name(target_storage_name)} (#{target_keys.join(', ')}) ON DELETE #{constraint_type} ON UPDATE #{constraint_type}) 146: end
Generates the SQL statement to destroy a constraint
@param [String] storage_name
name of table to constrain
@param [String] constraint_name
name of foreign key constraint
@return [String]
SQL DDL Statement to destroy a constraint
@api private
# File lib/data_mapper/constraints/adapters/do_adapter.rb, line 167 167: def destroy_constraints_statement(storage_name, constraint_name) 168: DataMapper::Ext::String.compress_lines( ALTER TABLE #{quote_name(storage_name)} DROP CONSTRAINT #{quote_name(constraint_name)}) 169: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.