Commit 938d0d6a authored by hellekin's avatar hellekin

Rationalize resource collections

- Fix Collection relationships
- Remove HABTM on sections
- Normalize Maps controllers
parent c1b92481
......@@ -16,6 +16,7 @@ class Api::V0::MapsController < ApplicationController
private
def model_types
%w(agent collection resources position taxonomy taxonomy.categories taxonomy.sections).freeze
%w(agent collection resources position
taxonomy taxonomy.categories taxonomy.sections).freeze
end
end
......@@ -6,7 +6,7 @@ class Collection < ApplicationRecord
translates :name, :summary, :description
belongs_to :agent, class_name: 'Agent'
has_many :resource_collections, dependent: :destroy
has_many :resource_collections, dependent: :destroy, source: :collection
with_options through: :resource_collections do
has_many :resources, source: :resource
end
......
......@@ -9,8 +9,8 @@ class Map < ApplicationRecord
belongs_to :collection
belongs_to :agent
has_many :collection_resources, through: :collection
with_options through: :collection_resources, source: :resource do
has_many :resource_collections, through: :collection, inverse_of: :collection
with_options through: :resource_collections, source: :resource do
has_many :resources
end
......
......@@ -97,12 +97,16 @@ end
#
# id :bigint(8) not null, primary key
# box :json
# elevation :decimal(6, 2)
# elevation :decimal(7, 2)
# geo_type :string
# geometry :text
# geometry :geometry({:srid= geometry, 0
# latitude :decimal(9, 7)
# longitude :decimal(10, 7)
# radius :bigint(8)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_positions_on_geometry (geometry) USING gist
#
......@@ -36,7 +36,8 @@ class Resource < ApplicationRecord
has_many :resource_collections, dependent: :destroy
has_and_belongs_to_many :sections
has_many :resource_sections, dependent: :destroy
has_many :sections, through: :resource_sections, source: :section
end
# == Schema Information
......
# frozen_string_literal: true
class ResourceCollection < ApplicationRecord
belongs_to :resource
belongs_to :collection
belongs_to :resource, inverse_of: :resource_collections
belongs_to :collection, inverse_of: :resource_collections
end
# == Schema Information
......
# frozen_string_literal: true
class ResourceSection < ApplicationRecord
belongs_to :resource, polymorphic: true
belongs_to :section, counter_cache: true
end
# == Schema Information
#
# Table name: resource_sections
#
# id :bigint(8) not null, primary key
# resource_type :string
# resource_id :bigint(8)
# section_id :bigint(8)
#
# Indexes
#
# index_resource_sections_on_resource_type_and_resource_id (resource_type,resource_id)
# index_resource_sections_on_section_id (section_id)
#
# Foreign Keys
#
# fk_rails_... (section_id => sections.id)
#
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment