title: psql query in ruby model
body: <p>How to implement the following query in ruby model:</p>
  
  <pre><code>select * from outsources where folder_id = 28 and id != 44 and returned = false;
  </code></pre>
  
  <p>Here,how to access the current record id instead of a particular id</p>
  
  <p>Here is the outsource model:</p>
  
  <pre><code>class Outsource &lt; ActiveRecord::Base
    include Workflow
  
    workflow_column :status
  
    # constants
    belongs_to :client
    belongs_to :vendor
    belongs_to :folder
  
    after_initialize :init_dates
    before_update :init_return_date
  
    validate :folder_availability, if: proc { |i| i.folder.present? }
    validates_presence_of :folder_id, :vendor_id
  
    scope :open_transactions, -&gt; { where(status: [OUTSOURCED, FINISHED, CANCELED]) }
  
    workflow do
      state :outsourced
    end
  
    private
  
    def folder_availability
      errors.add(:folder_id, 'This folder is not available for outsource. Please review.') \
        if self.folder.completed? || self.folder.abandoned? || self.folder.canceled? || self.folder.closed?
    end
  
    def init_dates
      self.outsource_date ||= Date.today
    end
  
    def init_return_date
      self.return_date ||= Date.today
    end
  end
  </code></pre>
  
  <p>Here current record is Outsource and Folder. In which same folder belongs to multiple outsources.I need to change the status from outsource to in-progress when all the outsourced folders returned value become true</p>