Class: Rhubarb::Reference
- Inherits:
-
Object
- Object
- Rhubarb::Reference
- Defined in:
- lib/rhubarb/reference.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#referent ⇒ Object
readonly
Returns the value of attribute referent.
Instance Method Summary collapse
-
#initialize(klass, options = {}) ⇒ Reference
constructor
Creates a new Reference object, modeling a foreign-key relationship to another table.
- #managed_ref? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(klass, options = {}) ⇒ Reference
Creates a new Reference object, modeling a foreign-key relationship to another table. klass
is a class that includes Persisting; options
is a hash of options, which include
- :column => name
-
specifies the name of the column to reference in
klass
(defaults to row id) - :on_delete => :cascade
-
specifies that deleting the referenced row in
klass
will delete all rows referencing that row through this reference
20 21 22 23 24 25 |
# File 'lib/rhubarb/reference.rb', line 20 def initialize(klass, ={}) @referent = klass @options = @options[:column] ||= "row_id" @column = [:column] end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
15 16 17 |
# File 'lib/rhubarb/reference.rb', line 15 def column @column end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/rhubarb/reference.rb', line 15 def @options end |
#referent ⇒ Object (readonly)
Returns the value of attribute referent.
15 16 17 |
# File 'lib/rhubarb/reference.rb', line 15 def referent @referent end |
Instance Method Details
#managed_ref? ⇒ Boolean
33 34 35 36 37 |
# File 'lib/rhubarb/reference.rb', line 33 def managed_ref? # XXX? return false if referent.class == String referent.ancestors.include? Persisting end |
#to_s ⇒ Object
27 28 29 30 31 |
# File 'lib/rhubarb/reference.rb', line 27 def to_s trigger = "" trigger = " on delete cascade" if [:on_delete] == :cascade "references #{@referent}(#{@column})#{trigger}" end |