From 194a551203e980c9b581f0e557e0d63dfb070faf Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 14 Jul 2015 16:15:25 +0300 Subject: [PATCH] Improve unbinded invoice scope #2539 --- app/models/invoice.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 585a74a36..f55851849 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -7,7 +7,9 @@ class Invoice < ActiveRecord::Base accepts_nested_attributes_for :invoice_items - scope :unbinded, -> { where('id NOT IN (SELECT invoice_id FROM account_activities)') } + scope :unbinded, lambda { + where('id NOT IN (SELECT invoice_id FROM account_activities where invoice_id IS NOT NULL)') + } attr_accessor :billing_email validates :billing_email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, allow_blank: true