Class: Ramen::Metadata::PrimaryKey
- Inherits:
-
RowDataGateway
- Object
- RowDataGateway
- Ramen::Metadata::PrimaryKey
- Defined in:
- lib/ramen/metadata/primary_key.rb
Overview
PrimaryKey contains meta-data about the primary key for a Table. The attributes are database engine specific.
Only primary_key_name is required by Ramen. See RowDataGateway for more information.
PrimaryKey also contains a collection of PrimaryKeyColumn objects. These are accessable by the column attribute.
See Database for a description of how PrimaryKey fits in the Ramen collection hierarchy.
Links: readme.txt; source
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparison, returns -1,0,+1, compares primary_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) ⇒ PrimaryKey
constructor
:section: Internal Methods The following methods are for Ramen’s internal use.
Methods inherited from RowDataGateway
Constructor Details
#initialize(record, database) ⇒ PrimaryKey
: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/primary_key.rb', line 50 def initialize( record, database ) super( record, database ) @columns = Ramen::RamenHash.new( PrimaryKeyColumn, 'column' ) end |
Instance Method Details
#<=>(other) ⇒ Object
Comparison, returns -1,0,+1, compares primary_key_name
25 26 27 |
# File 'lib/ramen/metadata/primary_key.rb', line 25 def <=> other Ramen::RowDataGateway.compare( primary_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/primary_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/primary_key.rb', line 59 def add_to( database ) database.schema[ self.table_schema ].table[ self.table_name ].set_primary_key( self ) end |
#column ⇒ Object
column() #=> RamenHash reference
This attribute provides access to a RamenHash of all PrimaryKeyColumn objects in the PrimaryKey. The hash is indexed by column_name and column_id (if available).
usage:
require 'lib/ramen'
db = Ramen.create( configuration )
schema = db.schema['HumanResources']
table = schema.table['Employee']
pk = table.pk['PK_Employee_EmployeeID']
pk_column = pk.column['EmployeeID'] #=> #<Ramen::PrimaryKeyColumn ...
42 43 44 |
# File 'lib/ramen/metadata/primary_key.rb', line 42 def column @columns end |