Class: Province
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Province
- Defined in:
- app/models/province.rb
Defined Under Namespace
Modules: Codes
Constant Summary collapse
- NO_PROVINCE_ID =
-1
- QUEBEC_PROVINCE_ID =
80
Class Method Summary collapse
- .find_by_code(code, country_id) ⇒ Object
- .find_or_create_by_description(description, country_id) ⇒ Object
Methods inherited from ApplicationRecord
define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection
Class Method Details
.find_by_code(code, country_id) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/models/province.rb', line 38 def find_by_code(code, country_id) result = where( country_id: country_id ).where( 'LOWER(province_code) LIKE LOWER(?)', code ) result&.first end |
.find_or_create_by_description(description, country_id) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/province.rb', line 17 def find_or_create_by_description(description, country_id) result = where( country_id: country_id ).where( 'description COLLATE Latin1_General_CI_AI LIKE ?', "%#{description}%" ) if result.empty? create!( country_id: country_id, province_code: description, description: description, creation_date: Time.now, modification_date: Time.now, created_by: 'admin', modified_by: 'admin' ) else result.first end end |