Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

do not destroy sent notifications when device is destroyed

  • Loading branch information...
commit eab5ddc2bd6a202d9d9a59b979ff711ef5c7d812 1 parent 2fea644
Greg Barnett authored
View
7 app/models/apn/device.rb
@@ -1,4 +1,4 @@
-# Represents an iPhone (or other APN enabled device).
+# Represents an iOS device that supports APN.
# An APN::Device can have many APN::Notification.
#
# In order for the APN::Feedback system to work properly you *MUST*
@@ -12,7 +12,8 @@ class APN::Device < APN::Base
belongs_to :app, :class_name => 'APN::App'
has_many :notifications, :class_name => 'APN::Notification'
- has_many :unsent_notifications, :class_name => 'APN::Notification', :conditions => 'sent_at is null'
+ has_many :sent_notifications, :class_name => 'APN::Notification', :conditions => 'sent_at IS NOT NULL', :dependent => :nullify
+ has_many :unsent_notifications, :class_name => 'APN::Notification', :conditions => 'sent_at IS NULL', :dependent => :destroy
validates_uniqueness_of :token, :scope => :app_id
validates_format_of :token, :with => /^[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}$/
@@ -46,4 +47,4 @@ def set_last_registered_at
self.last_registered_at = Time.now #if self.last_registered_at.nil?
end
-end
+end
View
2  app/models/apn/notification.rb
@@ -38,6 +38,8 @@ class APN::Notification < APN::Base
belongs_to :device, :class_name => 'APN::Device'
has_one :app, :class_name => 'APN::App', :through => :device
+
+ scope :unsent, where(:sent_at => nil)
# returns a more or less human readable version of the error_response_status_code
def apn_status
View
9 lib/generators/templates/apn_migrations/013_allow_null_device_id_on_notifications.rb
@@ -0,0 +1,9 @@
+class AllowNullDeviceIdOnNotifications < ActiveRecord::Migration
+ def self.up
+ change_column(:apn_notifications, :device_id, :integer)
+ end
+
+ def self.down
+ change_column(:apn_notifications, :device_id, :integer, :null => false)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.