Class: DbSchema::Definitions::ForeignKey
- Inherits:
-
Object
- Object
- DbSchema::Definitions::ForeignKey
- Defined in:
- lib/db_schema/definitions/foreign_key.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on_delete ⇒ Object
readonly
Returns the value of attribute on_delete.
-
#on_update ⇒ Object
readonly
Returns the value of attribute on_update.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #deferrable? ⇒ Boolean
-
#initialize(name:, fields:, table:, keys: [], on_update: :no_action, on_delete: :no_action, deferrable: false) ⇒ ForeignKey
constructor
A new instance of ForeignKey.
- #options ⇒ Object
- #references_primary_key? ⇒ Boolean
Constructor Details
#initialize(name:, fields:, table:, keys: [], on_update: :no_action, on_delete: :no_action, deferrable: false) ⇒ ForeignKey
Returns a new instance of ForeignKey.
7 8 9 10 11 12 13 14 15 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 7 def initialize(name:, fields:, table:, keys: [], on_update: :no_action, on_delete: :no_action, deferrable: false) @name = name @fields = fields @table = table @keys = keys @on_update = on_update @on_delete = on_delete @deferrable = deferrable end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
5 6 7 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 5 def fields @fields end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
5 6 7 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 5 def keys @keys end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 5 def name @name end |
#on_delete ⇒ Object (readonly)
Returns the value of attribute on_delete.
5 6 7 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 5 def on_delete @on_delete end |
#on_update ⇒ Object (readonly)
Returns the value of attribute on_update.
5 6 7 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 5 def on_update @on_update end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
5 6 7 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 5 def table @table end |
Instance Method Details
#deferrable? ⇒ Boolean
21 22 23 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 21 def deferrable? @deferrable end |
#options ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 25 def { deferrable: deferrable?, name: name, on_delete: on_delete, on_update: on_update }.tap do || [:key] = keys unless references_primary_key? end end |
#references_primary_key? ⇒ Boolean
17 18 19 |
# File 'lib/db_schema/definitions/foreign_key.rb', line 17 def references_primary_key? keys.empty? end |