Class: ActiveRecord::Associations::HasOneAssociation

Inherits:
BelongsToAssociation
  • Object
show all
Defined in:
lib/active_record/connection_adapters/ibm_db_pstmt.rb

Instance Method Summary collapse

Instance Method Details

#construct_sqlObject



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1119

def construct_sql
  @finder_sql_param_array = []
  case
    when @reflection.options[:as]
      @finder_sql = 
        "#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = ? AND " +
        "#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = ?"
      @finder_sql_param_array << owner_quoted_id
      @finder_sql_param_array << @owner.class.quote_value(@owner.class.base_class.name.to_s)
    else
      @finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = ?"
      @finder_sql_param_array << owner_quoted_id
  end
    if conditions
      condition, *parameters = conditions
      @finder_sql << " AND (#{condition})"
      @finder_sql_param_array = @finder_sql_param_array + parameters unless parameters.nil?
    end
end

#find_targetObject



1109
1110
1111
1112
1113
1114
1115
1116
1117
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1109

def find_target
  @reflection.klass.find(:first, 
    :conditions => [@finder_sql] + @finder_sql_param_array,
    :select     => @reflection.options[:select],
    :order      => @reflection.options[:order], 
    :include    => @reflection.options[:include],
    :readonly   => @reflection.options[:readonly]
  )
end