对于招聘应用程序,我有一个用户模型,它有很多common_app。
每个用户实际上只有一个common_app,但是如果将来有更多的用户,我会将其设置为一个has_many关联。
在这个普通的应用程序中,我正在考虑拥有以下数据->
user_id:integer
current_city:string
grad_year:integer
read_type:string
listen_speak:string
time_in_china:integer
desired_industry:(not sure, will be a multi-select picklist)
location_pref:(not sure, will be a multi-select picklist)不过,我对此感到困惑的是,应用程序的一部分功能是根据用户的答案过滤用户。
有了这种关联,我能根据用户的答案过滤所有用户吗?即grad_year是2005年的所有用户吗?
如果是,我将如何编写命令来做到这一点?
发布于 2013-12-13 08:01:41
class User < ActiveRecord::Base
has_many :apps
end
class App < ActiveRecord::Base
belongs_to :user
end
User.includes(:apps).where('apps.grad_year = 2005')https://stackoverflow.com/questions/20561561
复制相似问题