Class: KSToOne
Instance Attribute Summary collapse
-
#foreignField ⇒ Object
readonly
Returns the value of attribute foreignField.
-
#foreignTable ⇒ Object
readonly
Returns the value of attribute foreignTable.
-
#localField ⇒ Object
readonly
Returns the value of attribute localField.
-
#localTable ⇒ Object
readonly
Returns the value of attribute localTable.
Instance Method Summary collapse
- #get(parent) ⇒ Object
-
#initialize(*args) ⇒ KSToOne
constructor
A new instance of KSToOne.
- #join ⇒ Object
- #set(parent, child) ⇒ Object
Constructor Details
#initialize(*args) ⇒ KSToOne
Returns a new instance of KSToOne.
5 6 7 8 |
# File 'lib/kansas/ToOne.rb', line 5 def initialize(*args) @localTable, @localField, @foreignTable, @foreignField = args @foreignField = @foreignTable.primaries.first unless @foreignField != '' end |
Instance Attribute Details
#foreignField ⇒ Object (readonly)
Returns the value of attribute foreignField.
3 4 5 |
# File 'lib/kansas/ToOne.rb', line 3 def foreignField @foreignField end |
#foreignTable ⇒ Object (readonly)
Returns the value of attribute foreignTable.
3 4 5 |
# File 'lib/kansas/ToOne.rb', line 3 def foreignTable @foreignTable end |
#localField ⇒ Object (readonly)
Returns the value of attribute localField.
3 4 5 |
# File 'lib/kansas/ToOne.rb', line 3 def localField @localField end |
#localTable ⇒ Object (readonly)
Returns the value of attribute localTable.
3 4 5 |
# File 'lib/kansas/ToOne.rb', line 3 def localTable @localTable end |
Instance Method Details
#get(parent) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/kansas/ToOne.rb', line 10 def get(parent) if @foreignField != @foreignTable.primaries.first sql = "SELECT * FROM #{@foreignTable.table_name} " + "WHERE #{@foreignField} = '#{parent.row[@localField]}'" parent.context.select(@foreignTable, sql).first else parent.context.get_object(@foreignTable, [parent.row[@localField]]) end end |
#join ⇒ Object
25 26 27 |
# File 'lib/kansas/ToOne.rb', line 25 def join "#{@localTable.table_name}.#{@localField} = #{@foreignTable.table_name}.#{@foreignField}" end |
#set(parent, child) ⇒ Object
20 21 22 23 |
# File 'lib/kansas/ToOne.rb', line 20 def set(parent, child) parent.row[@localField] = child.row[@foreignField] parent.changed end |