rasti-db 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e666cc71839d82d36edfac7d7370d9f31e6d275
4
- data.tar.gz: 80a4c04065aa81c0f2c5c3935127d15c36a1127a
3
+ metadata.gz: 1d89eb87b65dc22b36bc3774325e96fc5170902a
4
+ data.tar.gz: 60baea5f7737a43060d54a5f8c8f8a35764f8e48
5
5
  SHA512:
6
- metadata.gz: 50fc211f54d91108ff10290deb0e7ade32cc045424c8228514fddd32c8d5fd3a64fa02e2e5fb3809db3d343f91a90ddd70d392c1eeec65cd5847c5fc5b3a9533
7
- data.tar.gz: 8b10f98acbc07463c72bffe2e50117236d882ae3eae0442bef02f4d47124a80a4e0cb52dfb5e31151f3d3b510b21d0489300e782846084ce6b4351f8479b22be
6
+ metadata.gz: 64105cfa6be8315080047c1447521f105b525a90e51627de77a988f88369cc461f5390c78c0b7262add692acea32fa36a6206a026c896e421ee8187e15935d08
7
+ data.tar.gz: 51842d19c1e5696299d85c1e001bc0a1b58ef791012394e75693cd0f113084d51b240d8e918666d20eb350f1e404d19fdc3a6955ceebbca017a73b38d91f8e0a
@@ -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|
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  module DB
3
- VERSION = '0.2.6'
3
+ VERSION = '0.2.7'
4
4
  end
5
5
  end
@@ -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 * 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))',
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 * 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))'
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.6
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-06 00:00:00.000000000 Z
11
+ date: 2017-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel