app/models/service_learning/service_learning_position.rb
def open_for_place(obj)
      unless obj.nil?
        where("#{obj.class.name.foreign_key} = ? AND (person_id <=> 0 OR person_id IS NULL) ", obj).lock(true).first rescue []
        #find(:all, :conditions => ["#{obj.class.name.foreign_key} = ? AND (person_id <=> 0 OR person_id IS NULL) ", obj], :limit => 1, :lock => true) rescue []
      else
        where("service_learning_course_id IS NULL AND (person_id <=> 0 OR person_id IS NULL) ").lock(true).first rescue []
        #find(:all, :conditions => ["service_learning_course_id IS NULL AND (person_id <=> 0 OR person_id IS NULL) "], :limit => 1, :lock => true) rescue []
      end
    end
# Limits ONLY ONE of placements to those associated with the passed object but _also_ still considered and "open slot" (i.e., person_id is null)
# To avoid race condiction by useing mysql FOR UPDATE # add pessimistic locking
Limits ONLY ONE of placements to those associated with the passed object but _also_ still considered and "open slot"
To avoid race condiction by useing mysql FOR UPDATE # add pessimistic locking
Limits ONLY ONE of placements to those associated with the passed object but _also_ still considered and " open slot " To avoid race condiction by useing mysql FOR UPDATE # add pessimistic locking
def open_for_place(obj)
      unless obj.nil?
        where("#{obj.class.name.foreign_key} = ? AND (person_id <=> 0 OR person_id IS NULL) ", obj).lock(true).first rescue []
      else
        where("service_learning_course_id IS NULL AND (person_id <=> 0 OR person_id IS NULL) ").lock(true).first rescue []
      end
    end
def open_for_place ( obj ) unless obj . nil? where ( "#{obj.class.name.foreign_key} = ? AND (person_id <=> 0 OR person_id IS NULL) " , obj ) . lock ( true ) . first rescue [ ] else where ( "service_learning_course_id IS NULL AND (person_id <=> 0 OR person_id IS NULL) " ) . lock ( true ) . first rescue [ ] end end
Limits ONLY ONE of placements to those associated with the passed object but _also_ still considered and "open slot" (i.e., person_id is null)
To avoid race condiction by useing mysql FOR UPDATE # add pessimistic locking
Limits ONLY ONE of placements to those associated with the passed object but _also_ still considered and " open slot " ( i . e . person_id is null ) To avoid race condiction by useing mysql FOR UPDATE # add pessimistic locking
#find(:all, :conditions => ["#{obj.class.name.foreign_key} = ? AND (person_id <=> 0 OR person_id IS NULL) ", obj], :limit => 1, :lock => true) rescue [] #find(:all, :conditions => ["service_learning_course_id IS NULL AND (person_id <=> 0 OR person_id IS NULL) "], :limit => 1, :lock => true) rescue []
obj