rasti-db 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rasti/db/relations.rb +7 -1
- data/lib/rasti/db/version.rb +1 -1
- data/spec/collection_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d89eb87b65dc22b36bc3774325e96fc5170902a
|
4
|
+
data.tar.gz: 60baea5f7737a43060d54a5f8c8f8a35764f8e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64105cfa6be8315080047c1447521f105b525a90e51627de77a988f88369cc461f5390c78c0b7262add692acea32fa36a6206a026c896e421ee8187e15935d08
|
7
|
+
data.tar.gz: 51842d19c1e5696299d85c1e001bc0a1b58ef791012394e75693cd0f113084d51b240d8e918666d20eb350f1e404d19fdc3a6955ceebbca017a73b38d91f8e0a
|
data/lib/rasti/db/relations.rb
CHANGED
@@ -124,6 +124,10 @@ module Rasti
|
|
124
124
|
@relation_collection_name ||= @options[:relation_collection_name] || [source_collection_class.collection_name, target_collection_class.collection_name].sort.join('_').to_sym
|
125
125
|
end
|
126
126
|
|
127
|
+
def qualified_target_collection_name(schema=nil)
|
128
|
+
schema.nil? ? target_collection_class.collection_name : Sequel.qualify(schema, target_collection_class.collection_name)
|
129
|
+
end
|
130
|
+
|
127
131
|
def qualified_relation_collection_name(schema=nil)
|
128
132
|
schema.nil? ? relation_collection_name : Sequel.qualify(schema, relation_collection_name)
|
129
133
|
end
|
@@ -138,13 +142,15 @@ module Rasti
|
|
138
142
|
join_rows = target_collection.dataset
|
139
143
|
.join(relation_name, target_foreign_key => target_collection_class.primary_key)
|
140
144
|
.where(Sequel.qualify(relation_name, source_foreign_key) => pks)
|
145
|
+
.select_all(qualified_target_collection_name(schema))
|
146
|
+
.select_append(Sequel.qualify(relation_name, source_foreign_key).as(:source_foreign_key))
|
141
147
|
.all
|
142
148
|
|
143
149
|
Relations.graph_to join_rows, relations, target_collection_class, db, schema
|
144
150
|
|
145
151
|
relation_rows = join_rows.each_with_object(Hash.new { |h,k| h[k] = [] }) do |row, hash|
|
146
152
|
attributes = row.select { |attr,_| target_collection_class.model.attributes.include? attr }
|
147
|
-
hash[row[source_foreign_key]] << target_collection_class.model.new(attributes)
|
153
|
+
hash[row[:source_foreign_key]] << target_collection_class.model.new(attributes)
|
148
154
|
end
|
149
155
|
|
150
156
|
rows.each do |row|
|
data/lib/rasti/db/version.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -467,11 +467,11 @@ describe 'Collection' do
|
|
467
467
|
stub_db.sqls.must_equal [
|
468
468
|
'SELECT * FROM custom_schema.posts',
|
469
469
|
'SELECT * FROM custom_schema.users WHERE (id IN (1, 2))',
|
470
|
-
'SELECT
|
470
|
+
'SELECT custom_schema.categories.*, custom_schema.categories_posts.post_id AS source_foreign_key FROM custom_schema.categories INNER JOIN custom_schema.categories_posts ON (custom_schema.categories_posts.category_id = custom_schema.categories.id) WHERE (custom_schema.categories_posts.post_id IN (3, 4))',
|
471
471
|
'SELECT * FROM custom_schema.comments WHERE (post_id IN (3, 4))',
|
472
472
|
'SELECT * FROM custom_schema.users WHERE (id IN (2, 1))',
|
473
473
|
'SELECT * FROM custom_schema.posts WHERE (user_id IN (1, 2))',
|
474
|
-
'SELECT
|
474
|
+
'SELECT custom_schema.categories.*, custom_schema.categories_posts.post_id AS source_foreign_key FROM custom_schema.categories INNER JOIN custom_schema.categories_posts ON (custom_schema.categories_posts.category_id = custom_schema.categories.id) WHERE (custom_schema.categories_posts.post_id IN (3, 4))'
|
475
475
|
]
|
476
476
|
end
|
477
477
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|