validates uniqueness of a field with scope not working

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hi,
      validates_uniqueness_of :title, :scope => where(posted_on:

      { "$gt" => posted_on.beginning_of_day, "$lte" => posted_on.end_of_day})
      is not working. Being title is a string field and posted_on is a datetime field. Actual problem is validate uniqueness of title in a day.

      If found an alternate solution.
      validates_uniqueness_of :title, if: -> { Ad.where(title: title, posted_on: { "$gt" => posted_on.beginning_of_day, "$lte" => posted_on.end_of_day}

      ).size > 0 }

      Can you suggest a better solution.

            Assignee:
            Dianna Hohensee (Inactive)
            Reporter:
            aashish kiran
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: