【发布时间】:2017-03-28 23:33:48
【问题描述】:
我遇到了一个奇怪的错误,希望有人能指出我正确的方向。我有一个名为 Organizations 的模型和一个名为 department 的属性,请参阅以下架构的摘录:
t.integer "department", default: 0
在我的模型内部已经为这个属性定义了我的枚举,因为我使用的是ActiveRecord::Enum,如下所示:
enum department: [:conferences, :design_teams, :services, :clubs, :events, :communications]
但是当我查询时,JobPosting.joins(job: :organization).where(organizations: { department: 'conferences' }) 我收到一条错误消息:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "conferences"
仅供参考:一个组织有_many Jobs,而 Job has_many JobPostings。
但是当我查询Organization.where(department: 'conferences') 时,它可以工作。
任何帮助将不胜感激。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 activerecord enums