diff options
| author | Vlatka Pavisic | 2017-01-02 16:22:30 +0100 |
|---|---|---|
| committer | Vlatka Pavisic | 2017-01-02 16:22:30 +0100 |
| commit | c246e91169a0acea798fba01bfb2d9a360ac3cb0 (patch) | |
| tree | edaa8b88b4d0ee1c13a8add5c1efc55b2c32408e /app/models/calendar.rb | |
| parent | 7657a10c7c4b126cdaabb779657e9a5270fc729d (diff) | |
| download | chouette-core-c246e91169a0acea798fba01bfb2d9a360ac3cb0.tar.bz2 | |
Refs #2265 : Calendar search by date
Diffstat (limited to 'app/models/calendar.rb')
| -rw-r--r-- | app/models/calendar.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/calendar.rb b/app/models/calendar.rb index fc339caad..b1fac536c 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -7,6 +7,8 @@ class Calendar < ActiveRecord::Base after_initialize :init_dates_and_date_ranges + scope :contains_date, ->(date) { where('date ? = any (dates) OR date ? <@ any (date_ranges)', date, date) } + def init_dates_and_date_ranges self.dates ||= [] self.date_ranges ||= [] @@ -31,6 +33,10 @@ class Calendar < ActiveRecord::Base errors.add(:dates, I18n.t('activerecord.errors.models.calendar.attributes.dates.date_in_dates')) if dates && dates.length > dates.uniq.length end + def self.ransackable_scopes(auth_object = nil) + [:contains_date] + end + class Period include ActiveAttr::Model @@ -78,11 +84,11 @@ class Calendar < ActiveRecord::Base def new_record? !persisted? end + def persisted? id.present? end - def mark_for_destruction self._destroy = true end @@ -153,6 +159,7 @@ class Calendar < ActiveRecord::Base def clear_periods @periods = nil end + private :clear_periods def self.new_from from |
