title: Rails" Is it possible to know operation(update, create) being performed within validation method?
body: <p>Platform: Rail 3.0
  Database: mysql 5.1</p>
  
  <p>Business requirement: Only one item of a product can be issued at a time. After a return of the issued item, a new item can be issued of same product. Multiple items from different products can be issued at a time.</p>
  
  <p>To implement the above business requirement, I am checking if there is already an item issued for the same product within the same date range (by checking to see if there is an overlap of the dates in my where below).</p>
  
  <pre><code>     class Item &lt; ActiveRecord::Base
           validate :validate_one_item_for_product
           def validate_one_item_for_product
                 items = Item.where( "issue_date &lt; ? and return_date &gt; ? and product_id = ?", return_date, issue_date, product_id)
                 errors.add( :base, "item already issued for this product, not returned yet") if items.size &gt; 0
           end
       end
  </code></pre>
  
  <p>Validation defined above works fine on create but in case of update i need to implement different logic. I do not want to define two methods for same requirement. so i want to implement checks with function based upon whether its update or create operation.Is there any way i can know if operation which triggered validate is update or delete?</p>