what default value of a date should be given that it returns all the record if user has not entered date in squeel

StackOverflow https://stackoverflow.com/questions/21452471

  •  04-10-2022
  •  | 
  •  

Question

I am using a squeel gem and I have a scenario that when user does not enter employee joining date then all the records should be returned else return record on the basis of employees joining date. my query is loke this :

date = Date.today Employee.joins { passports.visas }.where { (employees.joining_date.eq "%#{date}%")

so if date is not given by the user then what should I put the default value of date so that it retrieve all the record?

Was it helpful?

Solution

simply make call back

in Employee model before_create :joining_date

def joining_date self.joining_date = Date.today end

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top