【发布时间】:2025-12-31 20:10:02
【问题描述】:
我正在尝试创建一个查看空关联的范围。
我有 4 个课程:User、IdeaProject 和 UserJoins。
多个用户可以有相同的想法或相同的项目。
我想创建一个范围来隔离没有想法的用户。
Idea.rb
has_many :user_joins
has_many :users, through: :user_joins
项目.rb
has_many :user_joins
has_many :users, through: :user_joins
用户.rb
has_many :user_joins
has_many :ideas, through: user_joins, source: :imaginable, source_type: 'Idea'
has_many :projects, through: user_joins, source: :imaginable, source_type: 'Project'
scope :without_ideas, ->{
# I'm stuck here.
}
UserJoin.rb
belongs_to :imaginable, polymorphic: true
belongs_to :user
我正在使用Rails 3.2.17 和Ruby 2.0.0
有没有人想办法解决这个问题?
【问题讨论】:
标签: ruby-on-rails ruby activerecord scope associations