Sure feel free to change.  Maybe my left outer join was from a time when I was trying to immediately get the unsigned signatures.

I think there are already specs for this method -- just run them to make sure still works.

JP

On Nov 4, 2013, at 12:47 PM, Dantemss <notifications@github.com> wrote:

> In lib/fine_print.rb:
> 
> > +  # Accepts a hash containing:
> > +  #   - :names -- an array of contract names
> > +  #   - :user -- the user in question
> > +  # and returns an array of names for the contracts whose latest published
> > +  # version the given user has not signed.
> > +  #
> > +  def self.get_unsigned_contract_names(options={})
> > +    return [] if options[:names].blank? || options[:user].nil?
> > +    options[:names] = [options[:names]].flatten.collect{|name| name.to_s}
> > +
> > +    signed_contracts = FinePrint::Contract
> > +      .where(name: options[:names].collect{|name| name.to_s})
> > +      .where(is_latest:true)
> > +      .joins('LEFT OUTER JOIN fine_print_signatures ON fine_print_signatures.contract_id = fine_print_contracts.id')
> > +      .where("fine_print_signatures.user_id = #{options[:user].id}")
> > +      .where("fine_print_signatures.user_type = '#{options[:user].class.name}'")
> I think you can actually do all this without Squeel and without writing SQL.
> 
> signed_contracts = FinePrint::Contract
> .where(name: options[:names].collect{|name| name.to_s}, is_latest: true)
> .joins(:signatures)
> .where(signatures: {user_id: options[:user].id, user_type: options[:user].class.name}
> 
> I can change this for you if you'd like.
> 
> —
> Reply to this email directly or view it on GitHub.
>