ruby-on-rails-3 – ActiveRecord查询has_many:通过模型
发布时间:2020-12-16 21:13:39 所属栏目:百科 来源:网络整理
导读:如何在“has_many:through”关系中查询具有特定分支的公司? #company.rb has_many :branch_choices has_many :branches,:through = :branch_choices “查找所有分行ID为3的公司” 解决方法 Company.includes(:branches).where(:branches = {:id = 3}) 要么
如何在“has_many:through”关系中查询具有特定分支的公司?
#company.rb has_many :branch_choices has_many :branches,:through => :branch_choices “查找所有分行ID为3的公司” 解决方法Company.includes(:branches).where(:branches => {:id => 3}) 要么 Branch.find(3).companies UPDATE Company. joins("LEFT JOIN `branch_choices` ON `branch_choices`.`company_id` = `companies`.`id`"). where(:branch_choices => {:branch_id => 3}) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |