Class: Ramen::Metadata::ForeignKey
- Inherits:
-
RowDataGateway
- Object
- RowDataGateway
- Ramen::Metadata::ForeignKey
- Defined in:
- lib/ramen/metadata/foreign_key.rb
Overview
ForeignKey contains meta-data about foreign keys within a Table. The attributes are database engine specific.
Only foreign_key_name and foreign_key_id are required by Ramen. See RowDataGateway for more information.
ForeignKey also contains a collection of ForeignKeyColumn objects. These are accessable by the column attribute.
See Database for a description of how ForeignKey fits in the Ramen collection hierarchy.
Links: readme.txt; source
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparison, returns -1,0,+1, compares foreign_key_name.
-
#add_column(obj) ⇒ Object
add_column( obj ) #=> obj.
-
#add_to(database) ⇒ Object
add_to( database ).
-
#column ⇒ Object
column() #=> RamenHash reference.
-
#initialize(record, database) ⇒ ForeignKey
constructor
:section: Internal Methods The following methods are for Ramen’s internal use.
Methods inherited from RowDataGateway
Constructor Details
#initialize(record, database) ⇒ ForeignKey
:section: Internal Methods The following methods are for Ramen’s internal use. They are not intended for clients of Ramen to use.
50 51 52 53 |
# File 'lib/ramen/metadata/foreign_key.rb', line 50 def initialize( record, database ) super( record, database ) @columns = Ramen::RamenHash.new( ForeignKeyColumn, 'column' ) end |
Instance Method Details
#<=>(other) ⇒ Object
Comparison, returns -1,0,+1, compares foreign_key_name
25 26 27 |
# File 'lib/ramen/metadata/foreign_key.rb', line 25 def <=> other Ramen::RowDataGateway.compare( foreign_key_name, other ) end |
#add_column(obj) ⇒ Object
add_column( obj ) #=> obj
Adds the column to this table. Throws a RamenError if the obj is not a ForeignKeyColumn.
67 68 69 |
# File 'lib/ramen/metadata/foreign_key.rb', line 67 def add_column( obj ) @columns.add( obj ) end |
#add_to(database) ⇒ Object
add_to( database )
Add self to the given database. (Choosing Message; Double Dispatch pattern) (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
59 60 61 |
# File 'lib/ramen/metadata/foreign_key.rb', line 59 def add_to( database ) database.schema[ self.table_schema ].table[ self.table_name ].add_foreign_key( self ) end |
#column ⇒ Object
column() #=> RamenHash reference
This attribute provides access to a RamenHash of all ForeignKeyColumn objects in the ForeignKey. The hash is indexed by column_id and column_name.
usage:
require 'lib/ramen'
db = Ramen.create( configuration )
schema = db.schema['HumanResources']
table = schema.table['Employee']
fk = table.fk['FK_Employee_Contact_ContactID']
fk_column = fk.column['ContactID'] #=> #<Ramen::ForeignKeyColumn ...
42 43 44 |
# File 'lib/ramen/metadata/foreign_key.rb', line 42 def column @columns end |