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.
221 222 223 224 225 226 227 228 |
# File 'lib/xmigra/declarative_support/table.rb', line 221 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.
230 231 232 |
# File 'lib/xmigra/declarative_support/table.rb', line 230 def delete_rule @delete_rule end |
#referent ⇒ Object
Returns the value of attribute referent.
230 231 232 |
# File 'lib/xmigra/declarative_support/table.rb', line 230 def referent @referent end |
#update_rule ⇒ Object
Returns the value of attribute update_rule.
230 231 232 |
# File 'lib/xmigra/declarative_support/table.rb', line 230 def update_rule @update_rule end |
Instance Method Details
#constrained_colnames ⇒ Object
232 233 234 |
# File 'lib/xmigra/declarative_support/table.rb', line 232 def constrained_colnames columns.keys end |
#creation_sql ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/xmigra/declarative_support/table.rb', line 240 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
236 237 238 |
# File 'lib/xmigra/declarative_support/table.rb', line 236 def referenced_colnames columns.values end |