rails 中调用数据库函数

  # 根据底线维护周期计算当前维护周期的底线维护周期
  def calculate_current_maintenance_date
    deadline = ActiveRecord::Base.connection.execute("select calculate_current_maintenance_date(#{self.id}) as deadline")[0]["deadline"]
    if deadline.present?
      # record[0] = {"deadline"=>"2014-06-27 02:23:34.229208"}
      deadline.split(" ")[0]
    else
      nil
    end
  end

 

你可能感兴趣的:(Rails)