Skip to content

Commit

Permalink
Modelos Address y GeoState
Browse files Browse the repository at this point in the history
Nuevos modelos Address y GeoState para las direcciones geolocalizadas de Division y Organization.
  • Loading branch information
pol-ak committed May 21, 2024
1 parent 2d10c66 commit 81ec591
Show file tree
Hide file tree
Showing 14 changed files with 1,075 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/models/address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Address < ApplicationRecord
belongs_to :country
belongs_to :geo_state, optional: true, foreign_key: 'state_id'

validates :street_address, :country_id, :geo_lat, :geo_long, presence: true

has_many :divisions
has_many :organizations
end
3 changes: 3 additions & 0 deletions app/models/country.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Country < ApplicationRecord
belongs_to :default_currency, class_name: 'Currency'

has_many :addresses
has_many :geo_states

def division
Division.root # for permissions purposes, assume country model belongs to root division
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/division.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Division < ApplicationRecord

belongs_to :organization # the organization which represents this loan agent division

belongs_to :address, optional: true

mount_uploader :logo, LogoUploader

validate :parent_division_and_name
Expand Down
8 changes: 8 additions & 0 deletions app/models/geo_state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class GeoState < ApplicationRecord
belongs_to :country

has_many :addresses

validates :country_id, presence: true
validates :name, presence: true
end
1 change: 1 addition & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Organization < ApplicationRecord
belongs_to :division
belongs_to :country
belongs_to :primary_contact, class_name: 'Person'
belongs_to :address, optional: true

has_many :loans, dependent: :destroy
has_many :people, foreign_key: :primary_organization_id, dependent: :nullify
Expand Down
Loading

0 comments on commit 81ec591

Please sign in to comment.