Skip to content

Commit

Permalink
Rename JoinManagers
Browse files Browse the repository at this point in the history
  • Loading branch information
lgebhardt committed Apr 19, 2024
1 parent 9a9e917 commit 16ee576
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 91 deletions.
4 changes: 2 additions & 2 deletions lib/jsonapi-resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
require 'jsonapi/callbacks'
require 'jsonapi/link_builder'
require 'jsonapi/active_relation/adapters/join_left_active_record_adapter'
require 'jsonapi/active_relation/join_manager'
require 'jsonapi/active_relation/join_manager_v10'
require 'jsonapi/active_relation/join_manager_through_inverse'
require 'jsonapi/active_relation/join_manager_through_primary'
require 'jsonapi/resource_identity'
require 'jsonapi/resource_fragment'
require 'jsonapi/resource_tree'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module ActiveRelation

# Stores relationship paths starting from the resource_klass, consolidating duplicate paths from
# relationships, filters and sorts. When joins are made the table aliases are tracked in join_details
class JoinManager
class JoinManagerThroughInverse
attr_reader :resource_klass,
:source_relationship,
:resource_join_tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module ActiveRelation

# Stores relationship paths starting from the resource_klass, consolidating duplicate paths from
# relationships, filters and sorts. When joins are made the table aliases are tracked in join_details
class JoinManagerV10
class JoinManagerThroughPrimary
attr_reader :resource_klass,
:source_relationship,
:resource_join_tree,
Expand Down
38 changes: 19 additions & 19 deletions lib/jsonapi/active_relation_retrieval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ module ClassMethods
def find(filters, options)
sort_criteria = options.fetch(:sort_criteria) { [] }

join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
filters: filters,
sort_criteria: sort_criteria)
join_manager = ActiveRelation::JoinManagerThroughInverse.new(resource_klass: self,
filters: filters,
sort_criteria: sort_criteria)

paginator = options[:paginator]

Expand All @@ -42,8 +42,8 @@ def find(filters, options)
#
# @return [Integer] the count
def count(filters, options)
join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughInverse.new(resource_klass: self,
filters: filters)

records = apply_request_settings_to_records(records: records(options),
filters: filters,
Expand Down Expand Up @@ -103,11 +103,11 @@ def find_fragments(filters, options)

sort_criteria = options.fetch(:sort_criteria) { [] }

join_manager = ActiveRelation::JoinManager.new(resource_klass: resource_klass,
source_relationship: nil,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughInverse.new(resource_klass: resource_klass,
source_relationship: nil,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)

paginator = options[:paginator]

Expand Down Expand Up @@ -331,11 +331,11 @@ def find_related_fragments_from_inverse(source, source_relationship, options, co
end
end

join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
source_relationship: inverse_relationship,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughInverse.new(resource_klass: self,
source_relationship: inverse_relationship,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)

paginator = options[:paginator]

Expand Down Expand Up @@ -511,9 +511,9 @@ def count_related_from_inverse(source_resource, source_relationship, options)
filters = options.fetch(:filters, {})

# Joins in this case are related to the related_klass
join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
source_relationship: inverse_relationship,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughInverse.new(resource_klass: self,
source_relationship: inverse_relationship,
filters: filters)

records = apply_request_settings_to_records(records: records(options),
resource_klass: self,
Expand Down Expand Up @@ -648,7 +648,7 @@ def find_records_by_keys(keys, options)
end

def apply_request_settings_to_records(records:,
join_manager: ActiveRelation::JoinManager.new(resource_klass: self),
join_manager: ActiveRelation::JoinManagerThroughInverse.new(resource_klass: self),
resource_klass: self,
source_ids: nil,
filters: {},
Expand Down
6 changes: 3 additions & 3 deletions lib/jsonapi/active_relation_retrieval_v09.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def find_fragments(filters, options)
sort_criteria = options.fetch(:sort_criteria) { [] }
order_options = construct_order_options(sort_criteria)

join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
filters: filters,
sort_criteria: sort_criteria)
join_manager = ActiveRelation::JoinManagerThroughInverse.new(resource_klass: self,
filters: filters,
sort_criteria: sort_criteria)

options[:_relation_helper_options] = {
context: context,
Expand Down
46 changes: 23 additions & 23 deletions lib/jsonapi/active_relation_retrieval_v10.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ module ClassMethods
def find(filters, options)
sort_criteria = options.fetch(:sort_criteria) { [] }

join_manager = ActiveRelation::JoinManagerV10.new(resource_klass: self,
filters: filters,
sort_criteria: sort_criteria)
join_manager = ActiveRelation::JoinManagerThroughPrimary.new(resource_klass: self,
filters: filters,
sort_criteria: sort_criteria)

paginator = options[:paginator]

Expand All @@ -42,8 +42,8 @@ def find(filters, options)
#
# @return [Integer] the count
def count(filters, options)
join_manager = ActiveRelation::JoinManagerV10.new(resource_klass: self,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughPrimary.new(resource_klass: self,
filters: filters)

records = apply_request_settings_to_records(records: records(options),
filters: filters,
Expand Down Expand Up @@ -103,11 +103,11 @@ def find_fragments(filters, options)

sort_criteria = options.fetch(:sort_criteria) { [] }

join_manager = ActiveRelation::JoinManagerV10.new(resource_klass: resource_klass,
source_relationship: nil,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughPrimary.new(resource_klass: resource_klass,
source_relationship: nil,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)

paginator = options[:paginator]

Expand Down Expand Up @@ -234,9 +234,9 @@ def count_related(source_resource, relationship, options)
filters = options.fetch(:filters, {})

# Joins in this case are related to the related_klass
join_manager = ActiveRelation::JoinManagerV10.new(resource_klass: self,
source_relationship: relationship,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughPrimary.new(resource_klass: self,
source_relationship: relationship,
filters: filters)

records = apply_request_settings_to_records(records: records(options),
resource_klass: related_klass,
Expand Down Expand Up @@ -377,11 +377,11 @@ def find_related_monomorphic_fragments(source_fragments, relationship, options,
sort_criteria << { field: field, direction: sort[:direction] }
end

join_manager = ActiveRelation::JoinManagerV10.new(resource_klass: self,
source_relationship: relationship,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughPrimary.new(resource_klass: self,
source_relationship: relationship,
relationships: linkage_relationships.collect(&:name),
sort_criteria: sort_criteria,
filters: filters)

paginator = options[:paginator]

Expand Down Expand Up @@ -493,10 +493,10 @@ def find_related_polymorphic_fragments(source_fragments, relationship, options,
end
end

join_manager = ActiveRelation::JoinManagerV10.new(resource_klass: self,
source_relationship: relationship,
relationships: linkage_relationship_paths,
filters: filters)
join_manager = ActiveRelation::JoinManagerThroughPrimary.new(resource_klass: self,
source_relationship: relationship,
relationships: linkage_relationship_paths,
filters: filters)

paginator = options[:paginator]

Expand Down Expand Up @@ -626,7 +626,7 @@ def find_related_polymorphic_fragments(source_fragments, relationship, options,
end

def apply_request_settings_to_records(records:,
join_manager: ActiveRelation::JoinManagerV10.new(resource_klass: self),
join_manager: ActiveRelation::JoinManagerThroughPrimary.new(resource_klass: self),
resource_klass: self,
filters: {},
primary_keys: nil,
Expand Down
Loading

0 comments on commit 16ee576

Please sign in to comment.