Class: Partitioned::PartitionedBase::Configurator::Data::ForeignKey
- Inherits:
-
Object
- Object
- Partitioned::PartitionedBase::Configurator::Data::ForeignKey
- Defined in:
- lib/partitioned/partitioned_base/configurator/data.rb
Overview
represents a SQL foreign key reference
Instance Attribute Summary collapse
-
#referenced_field ⇒ Object
Returns the value of attribute referenced_field.
-
#referenced_table ⇒ Object
Returns the value of attribute referenced_table.
-
#referencing_field ⇒ Object
Returns the value of attribute referencing_field.
Class Method Summary collapse
-
.foreign_key_to_foreign_table_name(foreign_key_field) ⇒ String
Produce a table name from the name of the foreign key.
Instance Method Summary collapse
-
#initialize(referencing_field, referenced_table = nil, referenced_field = :id) ⇒ ForeignKey
constructor
A new instance of ForeignKey.
Constructor Details
#initialize(referencing_field, referenced_table = nil, referenced_field = :id) ⇒ ForeignKey
19 20 21 22 23 24 25 26 27 |
# File 'lib/partitioned/partitioned_base/configurator/data.rb', line 19 def initialize(referencing_field, referenced_table = nil, referenced_field = :id) @referencing_field = referencing_field @referenced_table = if referenced_table.nil? self.class.foreign_key_to_foreign_table_name(referencing_field) else referenced_table end @referenced_field = referenced_field end |
Instance Attribute Details
#referenced_field ⇒ Object
Returns the value of attribute referenced_field.
18 19 20 |
# File 'lib/partitioned/partitioned_base/configurator/data.rb', line 18 def referenced_field @referenced_field end |
#referenced_table ⇒ Object
Returns the value of attribute referenced_table.
18 19 20 |
# File 'lib/partitioned/partitioned_base/configurator/data.rb', line 18 def referenced_table @referenced_table end |
#referencing_field ⇒ Object
Returns the value of attribute referencing_field.
18 19 20 |
# File 'lib/partitioned/partitioned_base/configurator/data.rb', line 18 def referencing_field @referencing_field end |
Class Method Details
.foreign_key_to_foreign_table_name(foreign_key_field) ⇒ String
Produce a table name from the name of the foreign key. in rails, this really means “foo_id” should be mapped to “foos”, and “company_id” should be mapped to “companies”
36 37 38 |
# File 'lib/partitioned/partitioned_base/configurator/data.rb', line 36 def self.foreign_key_to_foreign_table_name(foreign_key_field) return ActiveSupport::Inflector::pluralize(foreign_key_field.to_s.sub(/_id$/,'')) end |