相关疑难解决方法(0)

在 Rails 6 中,如何向左外连接查找器添加条件?

I\xe2\x80\x99m 使用 Rails 6.1.4.4。我这个模型有一个 has_many

\n
class MyObject < ApplicationRecord\n\n    has_many :products, inverse_of: :application, as: :item\n
Run Code Online (Sandbox Code Playgroud)\n

如何编写执行左外连接并在 LEFT-OUTER-JOIN-ON 子句中添加条件的作用域?我已经求助于原始sql \xe2\x80\xa6

\n
scope :awaiting_funding, ->(resubmissions: false) {\n\n  joins("LEFT OUTER JOIN products on products.item_id = my_objects.id and products.product_type = 11 and products.item_type = \xe2\x80\x98MyObject\xe2\x80\x99\xe2\x80\x9d).where('products.id is null')\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但我想将其转换为更像 Rails 的查找器方法。

\n

finder scope ruby-on-rails left-join ruby-on-rails-6

3
推荐指数
1
解决办法
1510
查看次数