Class: Card::Query::RefSpec
Constant Summary collapse
- REFSPECS =
{ :refer_to => ['referer_id','referee_id',''], :link_to => ['referer_id','referee_id',"ref_type='L' AND"], :include => ['referer_id','referee_id',"ref_type='I' AND"], :link_to_missing=> ['referer_id','referee_id',"present = 0 AND ref_type='L'"], :referred_to_by => ['referee_id','referer_id',''], :linked_to_by => ['referee_id','referer_id',"ref_type='L' AND"], :included_by => ['referee_id','referer_id',"ref_type='I' AND"] }
Instance Attribute Summary
Attributes inherited from Spec
Instance Method Summary collapse
-
#initialize(key, cardspec) ⇒ RefSpec
constructor
A new instance of RefSpec.
- #to_sql(*args) ⇒ Object
Methods inherited from Spec
#cast_type, #match_prep, #quote, #safe_sql
Constructor Details
#initialize(key, cardspec) ⇒ RefSpec
Returns a new instance of RefSpec.
13 14 15 |
# File 'lib/card/query/ref_spec.rb', line 13 def initialize key, cardspec @key, @cardspec = key, cardspec end |
Instance Method Details
#to_sql(*args) ⇒ Object
17 18 19 20 21 |
# File 'lib/card/query/ref_spec.rb', line 17 def to_sql *args field1, field2, where = REFSPECS[ @key.to_sym ] and_where = @key != :link_to_missing && "#{ field2 } IN #{ @cardspec.to_sql }" %{(select #{field1} from card_references where #{where} #{and_where})} end |