I want to check if the time frame intersects with another one on a document update. It works on creation, but I'm having trouble to change anything.
This is what i have so far:
if Timetracking.where(:begin.lt => params[:timetracking][:end], :end.gt => params[:timetracking][:begin]) && Timetracking.find(params[:id]) != params[:id]
@error = 'Time overlapping with another entry'
render 'timetracking/edit'
else
do update stuff
end
My basic idea was to check if the time overlaps and if the id is something else than the one I'm updating. I also tried another Query without success:
if Timetracking.where(:begin.lt => params[:timetracking][:end], :end.gt => params[:timetracking][:begin], :id.ne => params[:id])
@error = 'Time overlapping with another entry'
render 'timetracking/edit'
else
do stuff
end
Now I'm a little bit stuck. Maybe someone could push me to the right direction, please. :) Oh, and I'm using Padrino.
Thank you.