Rails 3:可选 has_one 关联的范围
我有两个模型:销售和付款
class Sale < ActiveRecord::Base
has_one :payment
end
class SaleCancelation < ActiveRecord::Base
belongs_to :payment
end
我想创建两个范围,“付款”和“不付款”。
“with_ payment”工作起来很简单:
class Sale < ActiveRecord::Base
scope :with_payment, joins( :payment )
end
但是我如何创建一个范围来查找没有有关联付款的每笔销售?
I have two models: Sale and Payment
class Sale < ActiveRecord::Base
has_one :payment
end
class SaleCancelation < ActiveRecord::Base
belongs_to :payment
end
I want to create two scopes, "with payment" and "without payment".
"with_payment" works easyly:
class Sale < ActiveRecord::Base
scope :with_payment, joins( :payment )
end
But how can I create a scope that finds every sale that does not have an associated Payment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
How about:
另一种方法:
Another way to do it: