Ruby:ActiveRecord gem中的绑定是什么意思?

时间:2017-11-29 06:01:16

标签: ruby-on-rails ruby activerecord rails-activerecord

我在许多方法中看到了绑定作为参数,但没有任何文档。

e.g。 Rails Source code

def find_by_sql(sql, binds = [], preparable: nil, &block)
  result_set = connection.select_all(sanitize_sql(sql), "#{name} Load", binds, preparable: preparable)
  column_types = result_set.column_types.dup
  columns_hash.each_key { |k| column_types.delete k }
  message_bus = ActiveSupport::Notifications.instrumenter

  payload = {
    record_count: result_set.length,
    class_name: name
  }

  message_bus.instrument("instantiation.active_record", payload) do
    result_set.map { |record| instantiate(record, column_types, &block) }
  end
end
  1. binds是什么意思?
  2. 如何使用它?

0 个答案:

没有答案