Null property selection using named scopes/lambda in Ruby on Rails -


i have object jobbreakdown has_one :invoice. if jobbreakdown has invoice (i.e. invoice_id not nil) considered invoiced. if not, consider uninvoiced. users want able select drop down box invoiced or uninvoiced , have correct records show up.

how write named scope test , return right records? along lines of

named_scope :is_invoiced, lambda {|is_invoiced| {:conditions => :invoice.nil? == is_invoiced}} 

nb: using ruby 1.8.7, rails 2.3.5

i'm not sure, right syntax rails 2.x @ least it'll give idea of how that.

named_scope :is_invoiced, lambda { |is_invoiced| :condition => is_invoiced ? "invoice not null" : "invoice null" } 

or maybe this:

named_scope :is_invoiced, lambda { |is_invoiced| :condition => "invoice #{is_invoiced ? 'not' : ''} null" } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -