【发布时间】:2018-10-05 17:45:29
【问题描述】:
我有这样的关联:
class Ship < ApplicationRecord
has_many :captain_profiles
has_many :captains, through: :captain_profiles
end
class CaptainProfile < ApplicationRecord
belongs_to :captain
belongs_to :ship
end
class Captain < ApplicationRecord
has_one :captain_profile
has_many :schedules
end
class Schedule < ApplicationRecord
belongs_to :captain
end
而且我需要准备好出海的所有船只的清单。换句话说,我必须找到所有至少有一名船长的船,并且至少有一个船长。
我考虑合并两个内部连接,因为我需要具有船长和附表的船舶。
我尝试了Captain.includes(:schedules).where("schedule.id IS NOT NULL") 和 Ships,但它不起作用。有人可以解释一下我做错了什么,我该怎么做?
【问题讨论】:
标签: ruby-on-rails postgresql rails-activerecord