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



1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1180

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



1170
1171
1172
1173
1174
1175
1176
1177
1178
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1170

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