azahara_schema 0.1.11 → 0.1.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee5aef33899add853399c0c393de05ca669875cf80fe5b4ee8b4b980bc125df8
4
- data.tar.gz: db7d83afd07a9dd04b1596a69b532cc280bca4795f532591d9598dbe751b5b5a
3
+ metadata.gz: af8c74a55165b64dd1028655871bbccd2df367faf7f8e140c2574d5e3823260c
4
+ data.tar.gz: 2b066a64fe4b33863562dad9d13c38dad1cd73f5460368f057851ef3dc873ab7
5
5
  SHA512:
6
- metadata.gz: 8b039a53e324f96b2bfca695916952a00e7b1399f42492ebe05725255642ffac8f126585029170a5e67512b18e8a26b102a6b1d8e3a8b6ec79bd6f89757d1ef6
7
- data.tar.gz: f6faf3bca1aad759a8d524c49563bd27f908f0421878306d6551ca4ca9da39929380c7ba0b4ed51dc649fdebd01d1cc4b9d26de5a96f45e7807e8cd2c96a52e1
6
+ metadata.gz: e68614299630ffafb7d870b3a8aea26df55ddccd8bea8ea5deaeebfcea6e1b2f76364c9b45a3b435ccaebf4b613f7ce824d52fb1e2721bc99866dab91394a784
7
+ data.tar.gz: 22bd14b10428e52aa5d61ccd404cc8ae892264548842c780abcecdd7bb9f19b4a72eddedfe1c34c9e0d10940d72fde20683664c4485cfde0fbc04028838e3f60
@@ -55,12 +55,27 @@ module AzaharaSchema
55
55
  { association.name => attribute.association_hash }
56
56
  end
57
57
 
58
+ def arel_join(parent=nil, join_type=::Arel::Nodes::OuterJoin, a_tbl=self.arel_table)
59
+ parent ||= a_tbl
60
+ joined = parent
61
+ case association.macro
62
+ when :has_many, :has_one
63
+ joined = parent.join(attribute.arel_table, join_type).on( attribute.arel_table[association.foreign_key].eq( a_tbl[model.primary_key] ) )
64
+ when :belongs_to
65
+ joined = parent.join(attribute.arel_table, join_type).on( attribute.arel_table[attribute.model.primary_key].eq( a_tbl[association.foreign_key] ) )
66
+ else
67
+ raise 'Unknown macro ' + association.macro.to_s
68
+ end
69
+ attribute.arel_join( joined )
70
+ end
71
+
58
72
  def arel_statement(operator, values)
59
73
  attribute.arel_statement(operator, values)
60
74
  end
61
75
 
62
76
  def add_join(scope)
63
- scope.includes(association_hash).references(association_hash)
77
+ # scope.left_outer_joins(association_hash)
78
+ scope.joins(arel_join.join_sources)
64
79
  end
65
80
 
66
81
  def add_preload(scope)
@@ -2,7 +2,7 @@ require 'azahara_schema/field_format'
2
2
 
3
3
  module AzaharaSchema
4
4
  class Attribute
5
- attr_accessor :name, :format, :model
5
+ attr_accessor :name, :format, :model, :table_alias
6
6
 
7
7
  def initialize(model, name, type)
8
8
  @name, @model = name, model
@@ -26,8 +26,12 @@ module AzaharaSchema
26
26
  format.format_name
27
27
  end
28
28
 
29
- def arel_field
30
- model.arel_table[filter_name]
29
+ def arel_table(t_alias=self.table_alias)
30
+ t_alias ? model.arel_table.alias(t_alias) : model.arel_table
31
+ end
32
+
33
+ def arel_field(t_alias=self.table_alias)
34
+ arel_table(t_alias)[filter_name]
31
35
  end
32
36
 
33
37
  def arel_sort_field
@@ -111,5 +115,9 @@ module AzaharaSchema
111
115
  {}
112
116
  end
113
117
 
118
+ def arel_join(parent=nil, join_type=::Arel::Nodes::OuterJoin, a_tbl=self.arel_table(self.table_alias))
119
+ parent
120
+ end
121
+
114
122
  end
115
123
  end
@@ -48,7 +48,8 @@ module AzaharaSchema
48
48
  end
49
49
  end
50
50
 
51
- def arel_field
51
+ # do not alias tables - let attributes derived from handle that
52
+ def arel_field(t_alias=nil)
52
53
  case derivation_method
53
54
  when :concat
54
55
  arel_fields = attributes.collect{|a| a.arel_field}
@@ -125,6 +125,7 @@ module AzaharaSchema
125
125
  def available_attributes
126
126
  unless @available_attributes
127
127
  initialize_available_attributes
128
+ @available_attributes.each{|at| at.table_alias = Array(association_path[1..-1]).collect(&:to_s).join('_').presence }
128
129
  end
129
130
  @available_attributes
130
131
  end
@@ -157,7 +158,7 @@ module AzaharaSchema
157
158
  end
158
159
 
159
160
  def association_path
160
- @association_path ||= parent_schema ? ( [association.name].concat(parent_schema.association_path) ) : []
161
+ @association_path ||= parent_schema ? ( parent_schema.association_path + [association.name] ) : [model.model_name.element.to_sym]
161
162
  end
162
163
 
163
164
  def available_associations
@@ -1,3 +1,3 @@
1
1
  module AzaharaSchema
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.12'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azahara_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-10 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.7.0
101
+ rubygems_version: 2.7.2
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Gem to support developement of rails application with schema over an entity