我刚刚将我的数据库从 mysql 更改为 postgres,我收到以下错误:
ActionView::Template::Error (PG::Error: ERROR: operator does not exist: character varying = integer
LINE 1: ...ELECT COUNT(*) FROM "agents" WHERE "agents"."client_id" = 1
做的时候
client.agents.count
我有一个数据的结构如下:客户端有几个代理,如果 ,则只能添加更多代理agents.count < X
,所以我正在使用类似client.agents.count
检索这个值并进行比较的东西,但我得到了那个错误。我需要使用手动 sql 来完成这项工作吗?还是我错过了一些愚蠢的东西?
谢谢您的意见
型号信息
class Agent < User
belongs_to :client
attr_accessible :client_id
validates :client_id, presence: true
end
class Client < User
attr_accessible :appId, :expire_date, :legacy, :url, :plan_id, :chat_window_color, :chat_head_color, :chat_box_container_color, :chat_box_color, :tab_message, :greeting, :please_wait_message, :send_message_button, :comments_label, :offline_message
belongs_to :plan
has_many :agents, :dependent => :destroy
has_secure_password
after_initialize :init
#omited validations
private
#BEGIN PRIVATE METHODS
end
都继承自用户
class User < ActiveRecord::Base
self.abstract_class = true
attr_accessible :email, :name, :password, :password_confirmation
attr_accessor :updating_password
has_secure_password
before_save { self.email.downcase! }
#the controller must set updating_password to FALSE to avoid validation
def should_update_password?
updating_password || new_record?
end
end