polymorphic_join 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/polymorphic_join/version.rb +1 -1
- data/lib/polymorphic_join.rb +18 -5
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c613dd44e44c5926f53a7563876aa768be0a1c4ed93d7a5b6d466f288d225c14
|
4
|
+
data.tar.gz: b11dca1df7bbe4e17d8017ba7cb929151bd1373e95ab6f11fcb109a33bd48938
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 572ccc4a2074c1a8ec8a46cfe9f286516e4ae412f31f1ed0376ad746dc051d87f0cfbb3d5a9303ca962cada9129da83fd84aa79870c948c7190cd27a7e4aade8
|
7
|
+
data.tar.gz: bd8efc9ef21a1d92919069ed39fa39f3b476258d46b49bdf57bb3b98bd623b10e6c2baed676bb2d1306b033c984a7d48f1733be584b06551d6fe97a9711aa63d
|
data/lib/polymorphic_join.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# rubocop:disable MethodLength, AbcSize
|
1
|
+
# rubocop:disable MethodLength, AbcSize, ModuleLength
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'polymorphic_join/version'
|
@@ -73,12 +73,14 @@ module PolymorphicJoin
|
|
73
73
|
)
|
74
74
|
end
|
75
75
|
|
76
|
-
polymorphic_union_scope(
|
76
|
+
polymorphic_union_scope(
|
77
|
+
type, polymorphic[:refs], *joins_statements
|
78
|
+
)
|
77
79
|
end
|
78
80
|
|
79
81
|
protected
|
80
82
|
|
81
|
-
def polymorphic_union_scope(
|
83
|
+
def polymorphic_union_scope(type, refs, *scopes)
|
82
84
|
union = scopes[0]
|
83
85
|
t2 = arel_table
|
84
86
|
|
@@ -88,8 +90,20 @@ module PolymorphicJoin
|
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
93
|
+
types = type.to_s.pluralize
|
91
94
|
t1 = arel_table.create_table_alias(union, types)
|
92
|
-
from(
|
95
|
+
from(
|
96
|
+
t2.create_join(
|
97
|
+
t1,
|
98
|
+
t2.create_on(
|
99
|
+
t1[:id].eq(t2["#{type}_id".to_sym]).and(
|
100
|
+
t2["#{type}_type"].in(
|
101
|
+
refs.collect { |x| x.to_s.singularize.classify }
|
102
|
+
)
|
103
|
+
)
|
104
|
+
)
|
105
|
+
)
|
106
|
+
).distinct
|
93
107
|
end
|
94
108
|
|
95
109
|
def retrieve_all_polymorphic_types(type)
|
@@ -104,7 +118,6 @@ module PolymorphicJoin
|
|
104
118
|
poly_refs << (ref.is_a?(Symbol) ? ref : ref.keys.first)
|
105
119
|
end
|
106
120
|
|
107
|
-
puts refs.inspect
|
108
121
|
{
|
109
122
|
refs: poly_refs,
|
110
123
|
map_columns: refs.each_with_object({}) do |el, hash|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymorphic_join
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Huynh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
|
80
|
-
rubygems_version: 2.6.13
|
79
|
+
rubygems_version: 3.0.3
|
81
80
|
signing_key:
|
82
81
|
specification_version: 4
|
83
82
|
summary: This gem is used to do polymorphic join
|