core/app/models/gaku/address.rb in gaku-0.0.3 vs core/app/models/gaku/address.rb in gaku-0.1.0
- old
+ new
@@ -7,19 +7,11 @@
scope :deleted, -> { where(deleted: true) }
scope :students, -> { where(addressable_type: 'Gaku::Student') }
scope :teachers, -> { where(addressable_type: 'Gaku::Teacher') }
scope :guardians, -> { where(addressable_type: 'Gaku::Guardian') }
- has_paper_trail class_name: 'Gaku::Versioning::AddressVersion',
- on: [:update, :destroy],
- meta: {
- join_model: :join_model_name,
- joined_resource_id: :joined_resource_id
- }
- default_scope -> { where(deleted: false) }
-
validates :address1, :country, :city, presence: true
accepts_nested_attributes_for :country
before_create :ensure_first_primary, on: :create
@@ -30,29 +22,19 @@
addresses.where.not(id: id).update_all(primary: false)
update_attribute(:primary, true)
update_primary_address_field
end
- def soft_delete
- update_attributes(deleted: true, primary: false)
- decrement_count
- end
-
- def recover
- update_attribute(:deleted, false)
- increment_count
- end
-
def primary?
primary
end
- def join_model_name
- addressable_type
+ def self.primary
+ where(primary: true).first
end
- def joined_resource_id
- addressable_id
+ def self.secondary
+ where(primary: false)
end
def state_text
if state
state.abbr.blank? ? state.name : state.abbr