validates_overlap icon indicating copy to clipboard operation
validates_overlap copied to clipboard

Start_in date field cannot be nil

Open ohenrik opened this issue 9 years ago • 7 comments

It seems like the field containing the from date (start date) has to be present or the validation for overlapping dates will be fired. I assume this is a bug as not all records necessarily need to have a date period specified.

I'm using ruby version 2.2.1 and Rails 4.2.1

ohenrik avatar Jun 25 '15 07:06 ohenrik

Hi @ohenrik can you please paste a validation code from you model and some example of records, so I can simulate this situation?

robinbortlik avatar Jun 25 '15 08:06 robinbortlik

Hi

This is my validation method validates :start_date, :end_date, overlap: true

The records are simply just to have both the start and the end date empty. I think we have found the problem and I'm working on a fork. So if you want i can make a pull request a bit later?

ohenrik avatar Jun 25 '15 12:06 ohenrik

@ohenrik it would be awesome. So I will wait.

robinbortlik avatar Jun 25 '15 15:06 robinbortlik

Hi @ohenrik , did you do any progress with this issue? I'm afraid that what you found is not a bug, but a feature ;) I mean, if one record has end_at nil then it behaves like endless event. That's mean that there can't be any other record starting or ending after.

robinbortlik avatar Jun 30 '15 08:06 robinbortlik

And if you create record which have start_at => nil and end_at => nil then it behave like record beginning on the beginning of time and ending on the end of time. So there can't be any other record.

robinbortlik avatar Jun 30 '15 08:06 robinbortlik

Hi @robinbortlik, sorry not yet, haven't had time yet.

I agree that that is smart when eather start date or the end date is empty, since then for example an event can go on for ever. However when both of them are empty it should be considered as "no date range set" or else this validation will also validate that these fields are set if any other records exists. (e.g. validates presence of ). which is not always desired.

At least there should be an option to allows both dates to be empty and then not validate them.

ohenrik avatar Jun 30 '15 08:06 ohenrik

Also the validation message will often become confusing, since it is not obvious that and empty date means since forever and until forever. I feel that empty start and end dates should be eather allowed or validated with the "presence" validator.

ohenrik avatar Jun 30 '15 08:06 ohenrik