polyamorous 1.3.3 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/polyamorous.rb +13 -40
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +1 -9
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +2 -20
- data/lib/polyamorous/{activerecord_5.2_ruby_2 → activerecord_5.2.0_ruby_2}/join_association.rb +2 -10
- data/lib/polyamorous/{activerecord_5.2_ruby_2 → activerecord_5.2.0_ruby_2}/join_dependency.rb +3 -21
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb +12 -0
- data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +22 -0
- data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +81 -0
- data/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb +2 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +2 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +81 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +2 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +2 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +2 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +2 -0
- data/lib/polyamorous/version.rb +1 -1
- data/polyamorous.gemspec +2 -4
- metadata +19 -49
- data/.gitignore +0 -6
- data/.travis.yml +0 -59
- data/Gemfile +0 -33
- data/LICENSE +0 -20
- data/README.md +0 -21
- data/Rakefile +0 -17
- data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_association.rb +0 -76
- data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_dependency.rb +0 -96
- data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_association.rb +0 -2
- data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_dependency.rb +0 -4
- data/lib/polyamorous/activerecord_4.1_ruby_2/join_association.rb +0 -2
- data/lib/polyamorous/activerecord_4.1_ruby_2/join_dependency.rb +0 -3
- data/lib/polyamorous/activerecord_4.1_ruby_2/make_polyamorous_inner_joins.rb +0 -14
- data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_association.rb +0 -46
- data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_dependency.rb +0 -87
- data/lib/polyamorous/activerecord_4.2_ruby_2/join_association.rb +0 -2
- data/lib/polyamorous/activerecord_4.2_ruby_2/join_dependency.rb +0 -24
- data/spec/blueprints/articles.rb +0 -5
- data/spec/blueprints/comments.rb +0 -5
- data/spec/blueprints/notes.rb +0 -3
- data/spec/blueprints/people.rb +0 -4
- data/spec/blueprints/tags.rb +0 -3
- data/spec/helpers/polyamorous_helper.rb +0 -26
- data/spec/polyamorous/join_association_spec.rb +0 -54
- data/spec/polyamorous/join_dependency_spec.rb +0 -102
- data/spec/polyamorous/join_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -43
- data/spec/support/schema.rb +0 -98
data/lib/polyamorous/version.rb
CHANGED
data/polyamorous.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Polyamorous::VERSION
|
8
8
|
s.authors = ["Ernie Miller", "Ryan Bigg", "Jon Atack", "Xiang Li"]
|
9
9
|
s.email = ["ernie@erniemiller.org", "radarlistener@gmail.com", "jonnyatack@gmail.com", "bigxiang@gmail.com"]
|
10
|
-
s.homepage = "https://github.com/activerecord-hackery/polyamorous"
|
10
|
+
s.homepage = "https://github.com/activerecord-hackery/ransack/tree/master/polyamorous"
|
11
11
|
s.license = "MIT"
|
12
12
|
s.summary = %q{
|
13
13
|
Loves/is loved by polymorphic belongs_to associations, Ransack, Squeel, MetaSearch...
|
@@ -18,9 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
associations.
|
19
19
|
}
|
20
20
|
|
21
|
-
s.
|
22
|
-
|
23
|
-
s.add_dependency 'activerecord', '>= 3.0'
|
21
|
+
s.add_dependency 'activerecord', '>= 5.0'
|
24
22
|
s.add_development_dependency 'rspec', '~> 3'
|
25
23
|
s.add_development_dependency 'machinist', '~> 1.0.6'
|
26
24
|
s.add_development_dependency 'faker', '~> 1.6.5'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyamorous
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2019-08-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '5.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,47 +95,29 @@ executables: []
|
|
95
95
|
extensions: []
|
96
96
|
extra_rdoc_files: []
|
97
97
|
files:
|
98
|
-
- ".gitignore"
|
99
|
-
- ".travis.yml"
|
100
|
-
- Gemfile
|
101
|
-
- LICENSE
|
102
|
-
- README.md
|
103
|
-
- Rakefile
|
104
98
|
- lib/polyamorous.rb
|
105
|
-
- lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_association.rb
|
106
|
-
- lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_dependency.rb
|
107
|
-
- lib/polyamorous/activerecord_4.1_ruby_1.9/join_association.rb
|
108
|
-
- lib/polyamorous/activerecord_4.1_ruby_1.9/join_dependency.rb
|
109
|
-
- lib/polyamorous/activerecord_4.1_ruby_2/join_association.rb
|
110
|
-
- lib/polyamorous/activerecord_4.1_ruby_2/join_dependency.rb
|
111
|
-
- lib/polyamorous/activerecord_4.1_ruby_2/make_polyamorous_inner_joins.rb
|
112
|
-
- lib/polyamorous/activerecord_4.2_ruby_1.9/join_association.rb
|
113
|
-
- lib/polyamorous/activerecord_4.2_ruby_1.9/join_dependency.rb
|
114
|
-
- lib/polyamorous/activerecord_4.2_ruby_2/join_association.rb
|
115
|
-
- lib/polyamorous/activerecord_4.2_ruby_2/join_dependency.rb
|
116
99
|
- lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb
|
117
100
|
- lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb
|
118
101
|
- lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb
|
119
102
|
- lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb
|
120
|
-
- lib/polyamorous/activerecord_5.
|
121
|
-
- lib/polyamorous/activerecord_5.
|
103
|
+
- lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb
|
104
|
+
- lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb
|
105
|
+
- lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb
|
106
|
+
- lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb
|
107
|
+
- lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb
|
108
|
+
- lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb
|
109
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
|
110
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
|
111
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
|
112
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
|
113
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
|
114
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
|
122
115
|
- lib/polyamorous/join.rb
|
123
116
|
- lib/polyamorous/swapping_reflection_class.rb
|
124
117
|
- lib/polyamorous/tree_node.rb
|
125
118
|
- lib/polyamorous/version.rb
|
126
119
|
- polyamorous.gemspec
|
127
|
-
|
128
|
-
- spec/blueprints/comments.rb
|
129
|
-
- spec/blueprints/notes.rb
|
130
|
-
- spec/blueprints/people.rb
|
131
|
-
- spec/blueprints/tags.rb
|
132
|
-
- spec/helpers/polyamorous_helper.rb
|
133
|
-
- spec/polyamorous/join_association_spec.rb
|
134
|
-
- spec/polyamorous/join_dependency_spec.rb
|
135
|
-
- spec/polyamorous/join_spec.rb
|
136
|
-
- spec/spec_helper.rb
|
137
|
-
- spec/support/schema.rb
|
138
|
-
homepage: https://github.com/activerecord-hackery/polyamorous
|
120
|
+
homepage: https://github.com/activerecord-hackery/ransack/tree/master/polyamorous
|
139
121
|
licenses:
|
140
122
|
- MIT
|
141
123
|
metadata: {}
|
@@ -154,20 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
136
|
- !ruby/object:Gem::Version
|
155
137
|
version: '0'
|
156
138
|
requirements: []
|
157
|
-
|
158
|
-
rubygems_version: 2.6.13
|
139
|
+
rubygems_version: 3.0.2
|
159
140
|
signing_key:
|
160
141
|
specification_version: 4
|
161
142
|
summary: Loves/is loved by polymorphic belongs_to associations, Ransack, Squeel, MetaSearch...
|
162
|
-
test_files:
|
163
|
-
- spec/blueprints/articles.rb
|
164
|
-
- spec/blueprints/comments.rb
|
165
|
-
- spec/blueprints/notes.rb
|
166
|
-
- spec/blueprints/people.rb
|
167
|
-
- spec/blueprints/tags.rb
|
168
|
-
- spec/helpers/polyamorous_helper.rb
|
169
|
-
- spec/polyamorous/join_association_spec.rb
|
170
|
-
- spec/polyamorous/join_dependency_spec.rb
|
171
|
-
- spec/polyamorous/join_spec.rb
|
172
|
-
- spec/spec_helper.rb
|
173
|
-
- spec/support/schema.rb
|
143
|
+
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
sudo: false
|
4
|
-
cache: bundler
|
5
|
-
|
6
|
-
before_install:
|
7
|
-
- travis_retry gem install bundler
|
8
|
-
|
9
|
-
rvm:
|
10
|
-
- 2.5.0
|
11
|
-
- 2.4.3
|
12
|
-
- 2.3.6
|
13
|
-
- 2.2.9
|
14
|
-
|
15
|
-
env:
|
16
|
-
- RAILS=4-2-stable AREL=6-0-stable DB=sqlite
|
17
|
-
- RAILS=4-2-stable AREL=6-0-stable DB=mysql
|
18
|
-
- RAILS=4-2-stable AREL=6-0-stable DB=postgres
|
19
|
-
- RAILS=5-0-stable AREL=7-0-stable DB=sqlite
|
20
|
-
- RAILS=5-0-stable AREL=7-0-stable DB=mysql
|
21
|
-
- RAILS=5-0-stable AREL=7-0-stable DB=postgres
|
22
|
-
- RAILS=5-1-stable AREL=8-0-stable DB=sqlite
|
23
|
-
- RAILS=5-1-stable AREL=8-0-stable DB=mysql
|
24
|
-
- RAILS=5-1-stable AREL=8-0-stable DB=postgres
|
25
|
-
|
26
|
-
matrix:
|
27
|
-
include:
|
28
|
-
- rvm: 2.5.0
|
29
|
-
env: RAILS=master DB=sqlite3
|
30
|
-
- rvm: 2.5.0
|
31
|
-
env: RAILS=master DB=mysql
|
32
|
-
- rvm: 2.5.0
|
33
|
-
env: RAILS=master DB=postgres
|
34
|
-
|
35
|
-
- rvm: 2.4.3
|
36
|
-
env: RAILS=master DB=sqlite3
|
37
|
-
- rvm: 2.4.3
|
38
|
-
env: RAILS=master DB=mysql
|
39
|
-
- rvm: 2.4.3
|
40
|
-
env: RAILS=master DB=postgres
|
41
|
-
|
42
|
-
- rvm: 2.3.6
|
43
|
-
env: RAILS=master DB=sqlite3
|
44
|
-
- rvm: 2.3.6
|
45
|
-
env: RAILS=master DB=mysql
|
46
|
-
- rvm: 2.3.6
|
47
|
-
env: RAILS=master DB=postgres
|
48
|
-
|
49
|
-
- rvm: 2.2.9
|
50
|
-
env: RAILS=master DB=sqlite3
|
51
|
-
- rvm: 2.2.9
|
52
|
-
env: RAILS=master DB=mysql
|
53
|
-
- rvm: 2.2.9
|
54
|
-
env: RAILS=master DB=postgres
|
55
|
-
|
56
|
-
before_script:
|
57
|
-
- mysql -e 'create database ransack collate utf8_general_ci;'
|
58
|
-
- mysql -e 'use ransack;show variables like "%character%";show variables like "%collation%";'
|
59
|
-
- psql -c 'create database ransack;' -U postgres
|
data/Gemfile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
gemspec
|
3
|
-
|
4
|
-
gem 'rake'
|
5
|
-
|
6
|
-
rails = ENV['RAILS'] || 'master'
|
7
|
-
|
8
|
-
if rails == 'master'
|
9
|
-
arel = ENV['AREL'] || 'master'
|
10
|
-
arel_opts =
|
11
|
-
case arel
|
12
|
-
when /\// # A path
|
13
|
-
{ path: arel }
|
14
|
-
when /^v/ # A tagged version
|
15
|
-
{ git: 'git://github.com/rails/arel.git', tag: arel }
|
16
|
-
else
|
17
|
-
{ git: 'git://github.com/rails/arel.git', branch: arel }
|
18
|
-
end
|
19
|
-
gem 'arel', arel_opts
|
20
|
-
end
|
21
|
-
|
22
|
-
case rails
|
23
|
-
when /\// # A path
|
24
|
-
gem 'activerecord', path: "#{rails}/activerecord"
|
25
|
-
when /^v/ # A tagged version
|
26
|
-
git 'git://github.com/rails/rails.git', tag: rails do
|
27
|
-
gem 'activerecord'
|
28
|
-
end
|
29
|
-
else
|
30
|
-
git 'git://github.com/rails/rails.git', branch: rails do
|
31
|
-
gem 'activerecord'
|
32
|
-
end
|
33
|
-
end
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2011 Ernie Miller
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# Polyamorous
|
2
|
-
[![Build Status](https://travis-ci.org/activerecord-hackery/polyamorous.svg?branch=master)](https://travis-ci.org/activerecord-hackery/polyamorous)
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/polyamorous.svg)](https://badge.fury.io/rb/polyamorous)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/activerecord-hackery/polyamorous/badges/gpa.svg)](https://codeclimate.com/github/activerecord-hackery/polyamorous)
|
5
|
-
|
6
|
-
Polyamorous is an extraction of shared code from the
|
7
|
-
[Active Record Hackery](https://github.com/activerecord-hackery) gems
|
8
|
-
[Ransack](https://github.com/activerecord-hackery/ransack),
|
9
|
-
[Squeel](https://github.com/activerecord-hackery/squeel) and
|
10
|
-
[MetaSearch](https://github.com/activerecord-hackery/meta_search) by
|
11
|
-
[Ernie Miller](http://twitter.com/erniemiller) and maintained by
|
12
|
-
[Ryan Bigg](http://twitter.com/ryanbigg),
|
13
|
-
[Xiang Li](http://bigxiang.github.io),
|
14
|
-
[Jon Atack](http://twitter.com/jonatack),
|
15
|
-
[Sean Carroll](https://github.com/seanfcarroll) and a great little group of
|
16
|
-
[contributors]
|
17
|
-
(https://github.com/activerecord-hackery/polyamorous/graphs/contributors).
|
18
|
-
|
19
|
-
It is an internal library for extending various versions of Active Record with
|
20
|
-
polymorphism. There is no public API, so it's `:nodoc:`. Move along. Nothing to
|
21
|
-
see here.
|
data/Rakefile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec) do |rspec|
|
5
|
-
rspec.rspec_opts = ['--backtrace']
|
6
|
-
end
|
7
|
-
|
8
|
-
task :default => :spec
|
9
|
-
|
10
|
-
desc "Open an irb session with Ransack and the sample data used in specs"
|
11
|
-
task :console do
|
12
|
-
require 'irb'
|
13
|
-
require 'irb/completion'
|
14
|
-
require 'console'
|
15
|
-
ARGV.clear
|
16
|
-
IRB.start
|
17
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# active_record_3_and_4.0_ruby_1.9/join_association.rb
|
2
|
-
module Polyamorous
|
3
|
-
module JoinAssociationExtensions
|
4
|
-
include SwappingReflectionClass
|
5
|
-
def self.included(base)
|
6
|
-
base.class_eval do
|
7
|
-
alias_method_chain :initialize, :polymorphism
|
8
|
-
alias_method :equality_without_polymorphism, :==
|
9
|
-
alias_method :==, :equality_with_polymorphism
|
10
|
-
if base.method_defined?(:active_record)
|
11
|
-
alias_method :base_klass, :active_record
|
12
|
-
end
|
13
|
-
|
14
|
-
if ActiveRecord::VERSION::STRING =~ /^3\.0\./
|
15
|
-
alias_method_chain :association_join, :polymorphism
|
16
|
-
else
|
17
|
-
alias_method_chain :build_constraint, :polymorphism
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize_with_polymorphism(
|
23
|
-
reflection, join_dependency, parent = nil, polymorphic_class = nil
|
24
|
-
)
|
25
|
-
if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
|
26
|
-
swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
|
27
|
-
initialize_without_polymorphism(reflection, join_dependency, parent)
|
28
|
-
self.reflection.options[:polymorphic] = true
|
29
|
-
end
|
30
|
-
else
|
31
|
-
initialize_without_polymorphism(reflection, join_dependency, parent)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def equality_with_polymorphism(other)
|
36
|
-
equality_without_polymorphism(other) && base_klass == other.base_klass
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_constraint_with_polymorphism(
|
40
|
-
reflection, table, key, foreign_table, foreign_key
|
41
|
-
)
|
42
|
-
if reflection.options[:polymorphic]
|
43
|
-
build_constraint_without_polymorphism(
|
44
|
-
reflection, table, key, foreign_table, foreign_key
|
45
|
-
)
|
46
|
-
.and(foreign_table[reflection.foreign_type].eq(reflection.klass.name))
|
47
|
-
else
|
48
|
-
build_constraint_without_polymorphism(
|
49
|
-
reflection, table, key, foreign_table, foreign_key
|
50
|
-
)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def association_join_with_polymorphism
|
55
|
-
return @join if @Join
|
56
|
-
@join = association_join_without_polymorphism
|
57
|
-
if reflection.macro == :belongs_to && reflection.options[:polymorphic]
|
58
|
-
aliased_table = Arel::Table.new(
|
59
|
-
table_name,
|
60
|
-
as: @aliased_table_name,
|
61
|
-
engine: arel_engine,
|
62
|
-
columns: klass.columns
|
63
|
-
)
|
64
|
-
parent_table = Arel::Table.new(
|
65
|
-
parent.table_name,
|
66
|
-
as: parent.aliased_table_name,
|
67
|
-
engine: arel_engine,
|
68
|
-
columns: parent.base_klass.columns
|
69
|
-
)
|
70
|
-
@join << parent_table[reflection.options[:foreign_type]]
|
71
|
-
.eq(reflection.klass.name)
|
72
|
-
end
|
73
|
-
@join
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# active_record_3_and_4.0_ruby_1.9/join_dependency.rb
|
2
|
-
module Polyamorous
|
3
|
-
module JoinDependencyExtensions
|
4
|
-
def self.included(base)
|
5
|
-
base.class_eval do
|
6
|
-
alias_method_chain :build, :polymorphism
|
7
|
-
alias_method_chain :graft, :polymorphism
|
8
|
-
if base.method_defined?(:active_record)
|
9
|
-
alias_method :base_klass, :active_record
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def graft_with_polymorphism(*associations)
|
15
|
-
associations.each do |association|
|
16
|
-
unless join_associations.detect { |a| association == a }
|
17
|
-
if association.reflection.options[:polymorphic]
|
18
|
-
build(
|
19
|
-
Join.new(
|
20
|
-
association.reflection.name,
|
21
|
-
association.join_type,
|
22
|
-
association.reflection.klass
|
23
|
-
),
|
24
|
-
association.find_parent_in(self) || join_base,
|
25
|
-
association.join_type
|
26
|
-
)
|
27
|
-
else
|
28
|
-
build(
|
29
|
-
association.reflection.name,
|
30
|
-
association.find_parent_in(self) || join_base,
|
31
|
-
association.join_type
|
32
|
-
)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
self
|
37
|
-
end
|
38
|
-
|
39
|
-
if ActiveRecord::VERSION::STRING =~ /^3\.0\./
|
40
|
-
def _join_parts
|
41
|
-
@joins
|
42
|
-
end
|
43
|
-
else
|
44
|
-
def _join_parts
|
45
|
-
@join_parts
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def build_with_polymorphism(
|
50
|
-
associations, parent = nil, join_type = InnerJoin
|
51
|
-
)
|
52
|
-
case associations
|
53
|
-
when Join
|
54
|
-
parent ||= _join_parts.last
|
55
|
-
reflection = parent.reflections[associations.name] or
|
56
|
-
raise ::ActiveRecord::ConfigurationError,
|
57
|
-
"Association named '#{associations.name
|
58
|
-
}' was not found; perhaps you misspelled it?"
|
59
|
-
|
60
|
-
unless join_association = find_join_association_respecting_polymorphism(
|
61
|
-
reflection, parent, associations.klass
|
62
|
-
)
|
63
|
-
@reflections << reflection
|
64
|
-
join_association = build_join_association_respecting_polymorphism(
|
65
|
-
reflection, parent, associations.klass
|
66
|
-
)
|
67
|
-
join_association.join_type = associations.type
|
68
|
-
_join_parts << join_association
|
69
|
-
cache_joined_association(join_association)
|
70
|
-
end
|
71
|
-
|
72
|
-
join_association
|
73
|
-
else
|
74
|
-
build_without_polymorphism(associations, parent, join_type)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def find_join_association_respecting_polymorphism(reflection, parent, klass)
|
79
|
-
if association = find_join_association(reflection, parent)
|
80
|
-
unless reflection.options[:polymorphic]
|
81
|
-
association
|
82
|
-
else
|
83
|
-
association if association.base_klass == klass
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def build_join_association_respecting_polymorphism(reflection, parent, klass)
|
89
|
-
if reflection.options[:polymorphic] && klass
|
90
|
-
JoinAssociation.new(reflection, self, parent, klass)
|
91
|
-
else
|
92
|
-
JoinAssociation.new(reflection, self, parent)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|