mochigome 0.1.4 → 0.1.5
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.
- data/lib/mochigome_ver.rb +1 -1
- data/lib/model_graph.rb +10 -8
- data/lib/query.rb +1 -0
- data/test/unit/query_test.rb +8 -0
- metadata +3 -3
data/lib/mochigome_ver.rb
CHANGED
data/lib/model_graph.rb
CHANGED
@@ -22,14 +22,15 @@ module Mochigome
|
|
22
22
|
r += expr_models(e.send(m)) if e.respond_to?(m)
|
23
23
|
end
|
24
24
|
if e.respond_to?(:relation)
|
25
|
-
model = @table_to_model[e.relation.name]
|
26
|
-
|
25
|
+
model = @table_to_model[e.relation.name] or
|
26
|
+
raise ModelSetupError.new("Table lookup error: #{e.relation.name}")
|
27
27
|
r.add model
|
28
28
|
end
|
29
29
|
r
|
30
30
|
end
|
31
31
|
|
32
32
|
def relation_over_path(path)
|
33
|
+
update_assoc_graph(path)
|
33
34
|
real_path = path.map(&:to_real_model).uniq
|
34
35
|
# Project ensures that we return a Rel, not a Table, even if path is empty
|
35
36
|
rel = real_path.first.arel_table.project
|
@@ -73,8 +74,7 @@ module Mochigome
|
|
73
74
|
model_queue = models.dup
|
74
75
|
added_models = []
|
75
76
|
until model_queue.empty?
|
76
|
-
model = model_queue.shift
|
77
|
-
next if model.is_a?(SubgroupModel)
|
77
|
+
model = model_queue.shift.to_real_model
|
78
78
|
next if @graphed_models.include? model
|
79
79
|
@graphed_models.add model
|
80
80
|
added_models << model
|
@@ -101,6 +101,7 @@ module Mochigome
|
|
101
101
|
end
|
102
102
|
@table_to_model[model.table_name] = common.first
|
103
103
|
else
|
104
|
+
# TODO: Wait, isn't this just a base case of the above?
|
104
105
|
@table_to_model[model.table_name] = model
|
105
106
|
end
|
106
107
|
|
@@ -109,15 +110,16 @@ module Mochigome
|
|
109
110
|
each do |name, assoc|
|
110
111
|
# TODO: What about self associations?
|
111
112
|
# TODO: What about associations to the same model on different keys?
|
112
|
-
|
113
|
+
# TODO: How to deal with polymorphic? Check for matching has_X assoc?
|
114
|
+
next if assoc.options[:polymorphic]
|
113
115
|
foreign_model = assoc.klass
|
116
|
+
unless @graphed_models.include?(foreign_model)
|
117
|
+
model_queue.push(foreign_model)
|
118
|
+
end
|
114
119
|
edge = [model, foreign_model]
|
115
120
|
next if @assoc_graph.has_edge?(*edge) # Ignore duplicate assocs
|
116
121
|
@assoc_graph.add_edge(*edge)
|
117
122
|
@edge_relation_funcs[edge] = model.arelified_assoc(name)
|
118
|
-
unless @graphed_models.include?(foreign_model)
|
119
|
-
model_queue.push(foreign_model)
|
120
|
-
end
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
data/lib/query.rb
CHANGED
@@ -270,6 +270,7 @@ module Mochigome
|
|
270
270
|
cond = [cond]
|
271
271
|
end
|
272
272
|
if cond.is_a?(Array)
|
273
|
+
# TODO: Should group by type and use IN expressions
|
273
274
|
cond = cond.inject(nil) do |expr, obj|
|
274
275
|
subexpr = obj.class.arel_primary_key.eq(obj.id)
|
275
276
|
expr ? expr.or(subexpr) : subexpr
|
data/test/unit/query_test.rb
CHANGED
@@ -397,6 +397,14 @@ describe Mochigome::Query do
|
|
397
397
|
assert_equal 1, data_node["Expensive products"]
|
398
398
|
end
|
399
399
|
|
400
|
+
it "routes correctly from subgrouping to condition models" do
|
401
|
+
q = Mochigome::Query.new(
|
402
|
+
[Mochigome::SubgroupModel.new(Owner, :last_name)]
|
403
|
+
)
|
404
|
+
data_node = q.run([@product_a, @product_b])
|
405
|
+
assert_equal "Smith", (data_node/1).name
|
406
|
+
end
|
407
|
+
|
400
408
|
it "does not include hidden aggregation fields in output" do
|
401
409
|
q = Mochigome::Query.new(
|
402
410
|
[Owner, Store],
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mochigome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Mike Simon
|