Class: XMigra::DeclarativeSupport::Table::ForeignKey
- Inherits:
-
ColumnListConstraint
- Object
- Constraint
- ColumnListConstraint
- XMigra::DeclarativeSupport::Table::ForeignKey
- Defined in:
- lib/xmigra/declarative_support/table.rb
Constant Summary collapse
- IDENTIFIER =
"foreign key"- IMPLICIT_PREFIX =
"FK_"
Constants inherited from Constraint
Instance Attribute Summary collapse
-
#delete_rule ⇒ Object
Returns the value of attribute delete_rule.
-
#referent ⇒ Object
Returns the value of attribute referent.
-
#update_rule ⇒ Object
Returns the value of attribute update_rule.
Attributes inherited from ColumnListConstraint
Attributes inherited from Constraint
Instance Method Summary collapse
- #constrained_colnames ⇒ Object
- #creation_sql ⇒ Object
-
#initialize(name, constr_spec) ⇒ ForeignKey
constructor
A new instance of ForeignKey.
- #referenced_colnames ⇒ Object
Methods inherited from Constraint
bad_spec, #constraint_type, deserialize, each_type, implicit_type, inherited, #only_on_column_at_creation?, type_by_identifier
Constructor Details
#initialize(name, constr_spec) ⇒ ForeignKey
Returns a new instance of ForeignKey.
227 228 229 230 231 232 233 234 |
# File 'lib/xmigra/declarative_support/table.rb', line 227 def initialize(name, constr_spec) super(name, constr_spec) @referent = constr_spec['link to'] || Constraint.bad_spec( %Q{Foreign key constraint #{@name} does not specify "link to" (referent)} ) @update_rule = constr_spec['on update'].tap {|v| break v.upcase if v} @delete_rule = constr_spec['on delete'].tap {|v| break v.upcase if v} end |
Instance Attribute Details
#delete_rule ⇒ Object
Returns the value of attribute delete_rule.
236 237 238 |
# File 'lib/xmigra/declarative_support/table.rb', line 236 def delete_rule @delete_rule end |
#referent ⇒ Object
Returns the value of attribute referent.
236 237 238 |
# File 'lib/xmigra/declarative_support/table.rb', line 236 def referent @referent end |
#update_rule ⇒ Object
Returns the value of attribute update_rule.
236 237 238 |
# File 'lib/xmigra/declarative_support/table.rb', line 236 def update_rule @update_rule end |
Instance Method Details
#constrained_colnames ⇒ Object
238 239 240 |
# File 'lib/xmigra/declarative_support/table.rb', line 238 def constrained_colnames columns.keys end |
#creation_sql ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/xmigra/declarative_support/table.rb', line 246 def creation_sql "".tap do |result| result << creation_name_sql result << "FOREIGN KEY (#{constrained_colnames.join(', ')})" result << "\n REFERENCES #{referent} (#{referenced_colnames.join(', ')})" if update_rule result << "\n ON UPDATE #{update_rule}" end if delete_rule result << "\n ON DELETE #{delete_rule}" end end end |
#referenced_colnames ⇒ Object
242 243 244 |
# File 'lib/xmigra/declarative_support/table.rb', line 242 def referenced_colnames columns.values end |