aboutsummaryrefslogtreecommitdiff
path: root/app/models/section.rb
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-10-09 10:24:06 +0200
committerhellekin <hellekin@cepheide.org>2020-10-09 10:24:06 +0200
commitf48ce2f4c934fde3862cdad593eececc7a567d61 (patch)
treed2c874f8ebf4686d07052fa333032c04ef49e861 /app/models/section.rb
parent31850c6ca118b7828dbaa3ad1a87dab4287718f5 (diff)
downloadincommon-map-f48ce2f4c934fde3862cdad593eececc7a567d61.tar.gz
Add Classifications and Resource validations
- Turn `has_and_belongs_to_many` into `has_many :through`: now, resources and sections are related through Classifications. - Refactor usage of jsonb column to use ActiveRecord validations - Attention! store_accessor: NOTE: If you are using structured database data types (eg. PostgreSQL hstore/json, or MySQL 5.7+ json) there is no need for the serialization provided by .store. Simply use .store_accessor instead to generate the accessor methods. Be aware that these columns use a string keyed hash and do not allow access using a symbol. NOTE: The default validations with the exception of uniqueness will work. For example, if you want to check for uniqueness with hstore you will need to use a custom validation to handle it. https://api.rubyonrails.org/classes/ActiveRecord/Store.html
Diffstat (limited to 'app/models/section.rb')
-rw-r--r--app/models/section.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/app/models/section.rb b/app/models/section.rb
index 6cfeb38..7d26882 100644
--- a/app/models/section.rb
+++ b/app/models/section.rb
@@ -1,11 +1,12 @@
class Section < ApplicationRecord
belongs_to :category
has_one :taxonomy, through: :category
- has_and_belongs_to_many :resources
+ has_many :classifications
+ has_many :resources, through: :classifications
acts_as_list column: :rank, scope: :category
validates :name,
uniqueness: { scope: :category_id },
- length: 3..64
+ length: { in: 3..64 }
end