og 0.21.0 → 0.21.2
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/CHANGELOG +44 -0
- data/README +1 -1
- data/doc/RELEASES +6 -1
- data/lib/og.rb +24 -4
- data/lib/og/entity.rb +16 -7
- data/lib/og/manager.rb +0 -14
- data/lib/og/mixin/orderable.rb +7 -7
- data/lib/og/relation.rb +27 -28
- data/lib/og/store/memory.rb +2 -0
- data/lib/og/store/psql.rb +23 -2
- data/lib/og/store/sql.rb +63 -39
- data/lib/og/store/sqlite.rb +1 -1
- data/test/og/tc_inheritance.rb +11 -2
- data/test/og/tc_relation.rb +14 -1
- data/test/og/tc_store.rb +30 -18
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,5 +1,49 @@
|
|
1
|
+
28-07-2005 George Moschovitis <gm@navel.gr>
|
2
|
+
|
3
|
+
* lib/og/store/psql.rb: custom eval_og_allocate,
|
4
|
+
fixed inheritance porblem.
|
5
|
+
|
6
|
+
* lib/og/store/sql.rb: factored out eval_og_allocate.
|
7
|
+
|
8
|
+
* lib/og/store/*: fixed inheritance problem.
|
9
|
+
|
10
|
+
* lib/og/relation.rb (#enchant): fixed for polymorphic.
|
11
|
+
|
12
|
+
27-07-2005 George Moschovitis <gm@navel.gr>
|
13
|
+
|
14
|
+
* lib/og.rb: moved setup from manager.rb here,
|
15
|
+
(#escape): added helper.
|
16
|
+
|
17
|
+
* lib/og/relation.rb (#setup): refactored,
|
18
|
+
(#enchant): manually update the owner class to handle inherited
|
19
|
+
relations.
|
20
|
+
|
21
|
+
* slightly modified deborah's patch.
|
22
|
+
|
23
|
+
* test/og/tc_store.rb: updated,
|
24
|
+
added test for inhertiance/relarion problem.
|
25
|
+
|
26
|
+
* lib/og/mixin/orderable.rb: updated to latest, passes test.
|
27
|
+
|
28
|
+
* lib/og/store/sql.rb (#update_by_sql): implemented.
|
29
|
+
|
30
|
+
* lib/og/entity.rb (#update_by_sql): added.
|
31
|
+
(#update_properties): reimplemented [aleksi],
|
32
|
+
added some nice aliases,
|
33
|
+
(##update): use update_by_sql,
|
34
|
+
(##escape): implemented.
|
35
|
+
|
36
|
+
27-07-2005 Deborah Hooker <deb@ysabel.org>
|
37
|
+
|
38
|
+
* lib/og/store/sql.rb (#ordered_join_table_keys): implemented,
|
39
|
+
(#join): fix,
|
40
|
+
(#unjoin): fix,
|
41
|
+
(#eval_og_create_schema): fix.
|
42
|
+
|
1
43
|
24-07-2005 George Moschovitis <gm@navel.gr>
|
2
44
|
|
45
|
+
* --- VERSION 0.21.0 ---
|
46
|
+
|
3
47
|
* lib/og/relation/joins_many.rb: fixed the same bugs.
|
4
48
|
|
5
49
|
* lib/og/relation/has_many.rb: fixed find_options override
|
data/README
CHANGED
data/doc/RELEASES
CHANGED
data/lib/og.rb
CHANGED
@@ -68,19 +68,19 @@ require 'glue/configuration'
|
|
68
68
|
#
|
69
69
|
# * og_read
|
70
70
|
# * og_insert
|
71
|
-
#
|
72
|
-
#
|
71
|
+
# * og_update
|
72
|
+
# * og_delete
|
73
73
|
|
74
74
|
module Og
|
75
75
|
|
76
76
|
# The version.
|
77
77
|
|
78
|
-
Version = '0.21.
|
78
|
+
Version = '0.21.2'
|
79
79
|
|
80
80
|
# Library path.
|
81
81
|
|
82
82
|
LibPath = File.dirname(__FILE__)
|
83
|
-
|
83
|
+
|
84
84
|
# If true, check for implicit changes in the object
|
85
85
|
# graph. For example when you add an object to a parent
|
86
86
|
# the object might be removed from his previous parent.
|
@@ -139,6 +139,26 @@ module Og
|
|
139
139
|
# Pseudo type for binary data
|
140
140
|
|
141
141
|
class Blob; end
|
142
|
+
|
143
|
+
class << self
|
144
|
+
|
145
|
+
# Helper method, useful to initialize Og.
|
146
|
+
|
147
|
+
def setup(options = {})
|
148
|
+
m = @@manager = Manager.new(options)
|
149
|
+
m.manage_classes
|
150
|
+
return m
|
151
|
+
end
|
152
|
+
alias_method :connect, :setup
|
153
|
+
alias_method :options=, :setup
|
154
|
+
|
155
|
+
# Helper method.
|
156
|
+
|
157
|
+
def escape(str)
|
158
|
+
@@manager.store.escape(str)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
142
162
|
|
143
163
|
end
|
144
164
|
|
data/lib/og/entity.rb
CHANGED
@@ -27,9 +27,17 @@ module EntityMixin
|
|
27
27
|
self.class.ogmanager.store.update(self, options)
|
28
28
|
end
|
29
29
|
|
30
|
-
def update_properties(
|
31
|
-
self.class.ogmanager.store.
|
30
|
+
def update_properties(*properties)
|
31
|
+
self.class.ogmanager.store.update(self, :only => properties)
|
32
32
|
end
|
33
|
+
alias_method :update_property, :update_properties
|
34
|
+
alias_method :pupdate, :update_properties
|
35
|
+
|
36
|
+
def update_by_sql(set)
|
37
|
+
self.class.ogmanager.store.update_by_sql(self, set)
|
38
|
+
end
|
39
|
+
alias_method :update_sql, :update_by_sql
|
40
|
+
alias_method :supdate, :update_by_sql
|
33
41
|
|
34
42
|
# Reload this entity instance from the store.
|
35
43
|
|
@@ -70,12 +78,9 @@ module EntityMixin
|
|
70
78
|
alias_method :[], :load
|
71
79
|
alias_method :exist?, :load
|
72
80
|
|
73
|
-
def
|
74
|
-
ogmanager.store.
|
81
|
+
def update(set, options = nil)
|
82
|
+
ogmanager.store.update_by_sql(self, set, options)
|
75
83
|
end
|
76
|
-
alias_method :pupdate, :update_properties
|
77
|
-
alias_method :update_property, :update_properties
|
78
|
-
alias_method :batch_update, :update_properties
|
79
84
|
|
80
85
|
def find(options = {})
|
81
86
|
# gmosx, FIXME: this code seems too complex,
|
@@ -120,6 +125,10 @@ module EntityMixin
|
|
120
125
|
end
|
121
126
|
alias_method :delete!, :delete
|
122
127
|
|
128
|
+
def escape(str)
|
129
|
+
ogmanager.store.escape(str)
|
130
|
+
end
|
131
|
+
|
123
132
|
def transaction(&block)
|
124
133
|
ogmanager.store.transaction(&block)
|
125
134
|
end
|
data/lib/og/manager.rb
CHANGED
@@ -184,18 +184,4 @@ class Manager
|
|
184
184
|
|
185
185
|
end
|
186
186
|
|
187
|
-
class << self
|
188
|
-
|
189
|
-
# Helper method, useful to initialize Og.
|
190
|
-
|
191
|
-
def setup(options = {})
|
192
|
-
m = @@manager = Manager.new(options)
|
193
|
-
m.manage_classes
|
194
|
-
return m
|
195
|
-
end
|
196
|
-
alias_method :connect, :setup
|
197
|
-
alias_method :options=, :setup
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
187
|
end
|
data/lib/og/mixin/orderable.rb
CHANGED
@@ -115,12 +115,12 @@ module Orderable
|
|
115
115
|
|
116
116
|
def increment_position
|
117
117
|
@#{position} += 1
|
118
|
-
|
118
|
+
update_property(:#{position})
|
119
119
|
end
|
120
120
|
|
121
121
|
def decrement_position
|
122
122
|
@#{position} -= 1
|
123
|
-
|
123
|
+
update_property(:#{position})
|
124
124
|
end
|
125
125
|
|
126
126
|
def bottom_position
|
@@ -130,24 +130,24 @@ module Orderable
|
|
130
130
|
|
131
131
|
def set_top_position
|
132
132
|
@#{position} = 1
|
133
|
-
|
133
|
+
update_property(:#{position})
|
134
134
|
end
|
135
135
|
|
136
136
|
def set_bottom_position
|
137
137
|
@#{position} = bottom_position + 1
|
138
|
-
|
138
|
+
update_property(:#{position})
|
139
139
|
end
|
140
140
|
|
141
141
|
def increment_position_of_higher_items
|
142
|
-
#{base}.
|
142
|
+
#{base}.update("#{position}=(#{position} + 1)", #{cond_and}"#{position} < \#\{@#{position}\}")
|
143
143
|
end
|
144
144
|
|
145
145
|
def increment_position_of_all_items
|
146
|
-
#{base}.
|
146
|
+
#{base}.update("#{position}=(#{position} + 1)", #{cond})
|
147
147
|
end
|
148
148
|
|
149
149
|
def decrement_position_of_lower_items
|
150
|
-
#{base}.
|
150
|
+
#{base}.update("#{position}=(#{position} - 1)", #{cond_and}"#{position} > \#\{@#{position}\}")
|
151
151
|
end
|
152
152
|
}
|
153
153
|
|
data/lib/og/relation.rb
CHANGED
@@ -24,8 +24,19 @@ class Relation
|
|
24
24
|
raise 'Class of target not defined'
|
25
25
|
end
|
26
26
|
|
27
|
+
target_name = if collection
|
28
|
+
:target_plural_name
|
29
|
+
else
|
30
|
+
:target_singular_name
|
31
|
+
end
|
32
|
+
|
27
33
|
@options[:target_class] = args.pop
|
34
|
+
@options[target_name] = args.first unless args.empty?
|
35
|
+
|
36
|
+
setup()
|
37
|
+
end
|
28
38
|
|
39
|
+
def setup
|
29
40
|
if target_class == Object
|
30
41
|
# If the target class is just an Object mark that class
|
31
42
|
# as a polymorphic parent class.
|
@@ -55,9 +66,7 @@ class Relation
|
|
55
66
|
|
56
67
|
# Inflect the relation name.
|
57
68
|
|
58
|
-
unless
|
59
|
-
@options[target_name] = args.first
|
60
|
-
else
|
69
|
+
unless @options[target_name]
|
61
70
|
@options[target_name] = if collection
|
62
71
|
target_class.to_s.demodulize.underscore.downcase.plural.intern
|
63
72
|
else
|
@@ -123,26 +132,6 @@ class Relation
|
|
123
132
|
end
|
124
133
|
end
|
125
134
|
|
126
|
-
=begin
|
127
|
-
def resolve_target
|
128
|
-
if target_class.is_a?(Symbol)
|
129
|
-
c = owner_class.name.dup
|
130
|
-
c = "::" + c unless c =~ /::/
|
131
|
-
c.gsub!(/::.*$/, '::')
|
132
|
-
c << target_class.to_s
|
133
|
-
begin
|
134
|
-
klass = constant(c)
|
135
|
-
rescue
|
136
|
-
unless c == target_class
|
137
|
-
c = target_class
|
138
|
-
retry
|
139
|
-
end
|
140
|
-
end
|
141
|
-
@options[:target_class] = klass
|
142
|
-
end
|
143
|
-
end
|
144
|
-
=end
|
145
|
-
|
146
135
|
# Resolve a polymorphic target class.
|
147
136
|
# Overrided in subclasses.
|
148
137
|
|
@@ -163,16 +152,26 @@ class Relation
|
|
163
152
|
class << self
|
164
153
|
|
165
154
|
def resolve(klass, action)
|
166
|
-
if klass.
|
167
|
-
for relation in klass.
|
155
|
+
if relations = klass.metadata.relations
|
156
|
+
for relation in klass.metadata.relations
|
168
157
|
relation.send(action)
|
169
158
|
end
|
170
159
|
end
|
171
160
|
end
|
172
161
|
|
173
|
-
def enchant(klass)
|
174
|
-
if klass.
|
175
|
-
|
162
|
+
def enchant(klass)
|
163
|
+
if relations = klass.metadata.relations
|
164
|
+
# update inherited relations.
|
165
|
+
# gmosx, FIXME: implement a better fix/rethink this!
|
166
|
+
for relation in relations
|
167
|
+
relation[:owner_class] = klass
|
168
|
+
unless relation.target_class == Object or relation.target_class.metadata.polymorphic
|
169
|
+
relation.setup
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# enchant.
|
174
|
+
for relation in relations
|
176
175
|
relation.enchant unless relation.target_class == Object
|
177
176
|
end
|
178
177
|
end
|
data/lib/og/store/memory.rb
CHANGED
data/lib/og/store/psql.rb
CHANGED
@@ -126,7 +126,12 @@ class PsqlStore < SqlStore
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def enchant(klass, manager)
|
129
|
-
|
129
|
+
if sclass = klass.metadata.superclass
|
130
|
+
klass.const_set 'OGSEQ', "#{table(sclass.first)}_oid_seq"
|
131
|
+
else
|
132
|
+
klass.const_set 'OGSEQ', "#{table(klass)}_oid_seq"
|
133
|
+
end
|
134
|
+
|
130
135
|
klass.property :oid, Fixnum, :sql => 'serial PRIMARY KEY'
|
131
136
|
super
|
132
137
|
end
|
@@ -265,7 +270,7 @@ private
|
|
265
270
|
#++
|
266
271
|
|
267
272
|
def eval_og_insert(klass)
|
268
|
-
props = klass.properties
|
273
|
+
props = klass.properties.dup
|
269
274
|
values = props.collect { |p| write_prop(p) }.join(',')
|
270
275
|
|
271
276
|
if klass.metadata.superclass or klass.metadata.subclasses
|
@@ -287,6 +292,22 @@ private
|
|
287
292
|
}
|
288
293
|
end
|
289
294
|
|
295
|
+
def eval_og_allocate(klass)
|
296
|
+
if klass.metadata.subclasses
|
297
|
+
klass.module_eval %{
|
298
|
+
def self.og_allocate(res, row = 0)
|
299
|
+
Object.constant(res.getvalue(row, 0)).allocate
|
300
|
+
end
|
301
|
+
}
|
302
|
+
else
|
303
|
+
klass.module_eval %{
|
304
|
+
def self.og_allocate(res, row = 0)
|
305
|
+
self.allocate
|
306
|
+
end
|
307
|
+
}
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
290
311
|
def read_row(obj, res, res_row, row)
|
291
312
|
res.fields.each_with_index do |field, idx|
|
292
313
|
obj.instance_variable_set "@#{field}", res.getvalue(row, idx)
|
data/lib/og/store/sql.rb
CHANGED
@@ -146,7 +146,8 @@ module SqlUtils
|
|
146
146
|
|
147
147
|
def join_table_key(klass)
|
148
148
|
"#{klass.to_s.split('::').last.downcase}_oid"
|
149
|
-
end
|
149
|
+
end
|
150
|
+
|
150
151
|
def join_table_keys(class1, class2)
|
151
152
|
if class1 == class2
|
152
153
|
# Fix for the self-join case.
|
@@ -155,6 +156,11 @@ module SqlUtils
|
|
155
156
|
return join_table_key(class1), join_table_key(class2)
|
156
157
|
end
|
157
158
|
end
|
159
|
+
|
160
|
+
def ordered_join_table_keys(class1, class2)
|
161
|
+
first, second = join_class_ordering(class1, class2)
|
162
|
+
return join_table_keys(first, second)
|
163
|
+
end
|
158
164
|
|
159
165
|
def join_table_info(owner_class, target_class, postfix = nil)
|
160
166
|
owner_key, target_key = join_table_keys(owner_class, target_class)
|
@@ -265,39 +271,27 @@ class SqlStore < Store
|
|
265
271
|
|
266
272
|
klass.module_eval 'def self.table; OGTABLE; end'
|
267
273
|
|
268
|
-
|
269
|
-
# is an STI parent classes it reads the class from the
|
270
|
-
# resultset.
|
271
|
-
|
272
|
-
if klass.metadata.subclasses
|
273
|
-
klass.module_eval %{
|
274
|
-
def self.og_allocate(res)
|
275
|
-
Object.constant(res[0]).allocate
|
276
|
-
end
|
277
|
-
}
|
278
|
-
else
|
279
|
-
klass.module_eval %{
|
280
|
-
def self.og_allocate(res)
|
281
|
-
self.allocate
|
282
|
-
end
|
283
|
-
}
|
284
|
-
end
|
274
|
+
eval_og_allocate(klass)
|
285
275
|
|
286
276
|
super
|
287
277
|
|
288
278
|
unless klass.polymorphic_parent?
|
289
|
-
#
|
290
|
-
|
279
|
+
# precompile class specific lifecycle methods.
|
291
280
|
eval_og_create_schema(klass)
|
292
|
-
# create_table(klass) if Og.create_schema
|
293
|
-
klass.allocate.og_create_schema(self)
|
294
|
-
|
295
|
-
# precompile class specific lifecycle methods.
|
296
|
-
|
297
281
|
eval_og_insert(klass)
|
298
282
|
eval_og_update(klass)
|
299
|
-
eval_og_read(klass)
|
300
283
|
eval_og_delete(klass)
|
284
|
+
|
285
|
+
# create the table if needed.
|
286
|
+
klass.allocate.og_create_schema(self)
|
287
|
+
|
288
|
+
# finish up with eval_og_read, since we can't do that
|
289
|
+
# until after the table is created.
|
290
|
+
# Possible FIXME: This means you can't do any find-type
|
291
|
+
# operations in og_create_schema. Luckily, you're most
|
292
|
+
# likely to want to do .create, which is covered by
|
293
|
+
# og_insert.
|
294
|
+
eval_og_read(klass)
|
301
295
|
end
|
302
296
|
end
|
303
297
|
|
@@ -324,6 +318,9 @@ class SqlStore < Store
|
|
324
318
|
# If a properties collection is provided, only updates the
|
325
319
|
# selected properties. Pass the required properties as symbols
|
326
320
|
# or strings.
|
321
|
+
#--
|
322
|
+
# gmosx, THINH: condition is not really useful here :(
|
323
|
+
#++
|
327
324
|
|
328
325
|
def update(obj, options = nil)
|
329
326
|
if options and properties = options[:only]
|
@@ -347,7 +344,15 @@ class SqlStore < Store
|
|
347
344
|
# Update selected properties of an object or class of
|
348
345
|
# objects.
|
349
346
|
|
350
|
-
def update_properties(target,
|
347
|
+
def update_properties(target, *properties)
|
348
|
+
update(target, :only => properties)
|
349
|
+
end
|
350
|
+
alias_method :pupdate, :update_properties
|
351
|
+
alias_method :update_property, :update_properties
|
352
|
+
|
353
|
+
# More generalized method, also allows for batch updates.
|
354
|
+
|
355
|
+
def update_by_sql(target, set, options = nil)
|
351
356
|
set = set.gsub(/@/, '')
|
352
357
|
|
353
358
|
if target.is_a?(Class)
|
@@ -360,8 +365,6 @@ class SqlStore < Store
|
|
360
365
|
sql_update(sql)
|
361
366
|
end
|
362
367
|
end
|
363
|
-
alias_method :pupdate, :update_properties
|
364
|
-
alias_method :update_property, :update_properties
|
365
368
|
|
366
369
|
# Find a collection of objects.
|
367
370
|
#
|
@@ -425,7 +428,7 @@ class SqlStore < Store
|
|
425
428
|
|
426
429
|
def join(obj1, obj2, table, options = nil)
|
427
430
|
first, second = join_object_ordering(obj1, obj2)
|
428
|
-
first_key, second_key =
|
431
|
+
first_key, second_key = ordered_join_table_keys(obj1.class, obj2.class)
|
429
432
|
if options
|
430
433
|
exec "INSERT INTO #{table} (#{first_key},#{second_key}, #{options.keys.join(',')}) VALUES (#{first.pk},#{second.pk}, #{options.values.map { |v| quote(v) }.join(',')})"
|
431
434
|
else
|
@@ -438,7 +441,7 @@ class SqlStore < Store
|
|
438
441
|
|
439
442
|
def unjoin(obj1, obj2, table)
|
440
443
|
first, second = join_object_ordering(obj1, obj2)
|
441
|
-
first_key, second_key =
|
444
|
+
first_key, second_key = ordered_join_table_keys(obj1, obj2, table)
|
442
445
|
exec "DELETE FROM #{table} WHERE #{first_key}=#{first.pk} AND #{second_key}=#{second.pk}"
|
443
446
|
end
|
444
447
|
|
@@ -598,7 +601,7 @@ private
|
|
598
601
|
|
599
602
|
def eval_og_insert(klass)
|
600
603
|
pk = klass.pk_symbol
|
601
|
-
props = klass.properties
|
604
|
+
props = klass.properties.dup
|
602
605
|
values = props.collect { |p| write_prop(p) }.join(',')
|
603
606
|
|
604
607
|
if klass.metadata.superclass or klass.metadata.subclasses
|
@@ -696,12 +699,33 @@ private
|
|
696
699
|
def eval_og_create_schema(klass)
|
697
700
|
klass.module_eval %{
|
698
701
|
def og_create_schema(store)
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
+
if Og.create_schema
|
703
|
+
#{Aspects.gen_advice_code(:og_create_schema, klass.advices, :pre) if klass.respond_to?(:advices)}
|
704
|
+
store.send(:create_table, #{klass})
|
705
|
+
#{Aspects.gen_advice_code(:og_create_schema, klass.advices, :post) if klass.respond_to?(:advices)}
|
706
|
+
end
|
702
707
|
end
|
703
708
|
}
|
704
709
|
end
|
710
|
+
|
711
|
+
# Precompile a class specific allocate method. If this is an
|
712
|
+
# STI parent classes it reads the class from the resultset.
|
713
|
+
|
714
|
+
def eval_og_allocate(klass)
|
715
|
+
if klass.metadata.subclasses
|
716
|
+
klass.module_eval %{
|
717
|
+
def self.og_allocate(res, row = 0)
|
718
|
+
Object.constant(res[0]).allocate
|
719
|
+
end
|
720
|
+
}
|
721
|
+
else
|
722
|
+
klass.module_eval %{
|
723
|
+
def self.og_allocate(res, row = 0)
|
724
|
+
self.allocate
|
725
|
+
end
|
726
|
+
}
|
727
|
+
end
|
728
|
+
end
|
705
729
|
|
706
730
|
# :section: Misc methods.
|
707
731
|
|
@@ -810,7 +834,7 @@ private
|
|
810
834
|
offset = obj.class.properties.size
|
811
835
|
|
812
836
|
for rel in join_relations
|
813
|
-
rel_obj = rel[:target_class].og_allocate(res_row)
|
837
|
+
rel_obj = rel[:target_class].og_allocate(res_row, row)
|
814
838
|
rel_obj.og_read(res_row, row, offset)
|
815
839
|
offset += rel_obj.class.properties.size
|
816
840
|
obj.instance_variable_set("@#{rel[:name]}", rel_obj)
|
@@ -830,7 +854,7 @@ private
|
|
830
854
|
|
831
855
|
res_row = res.next
|
832
856
|
|
833
|
-
obj = klass.og_allocate(res_row)
|
857
|
+
obj = klass.og_allocate(res_row, 0)
|
834
858
|
|
835
859
|
if options and options[:select]
|
836
860
|
read_row(obj, res, res_row, 0)
|
@@ -860,13 +884,13 @@ private
|
|
860
884
|
|
861
885
|
if options and options[:select]
|
862
886
|
res.each_row do |res_row, row|
|
863
|
-
obj = klass.og_allocate(res_row)
|
887
|
+
obj = klass.og_allocate(res_row, row)
|
864
888
|
read_row(obj, res, res_row, row)
|
865
889
|
objects << obj
|
866
890
|
end
|
867
891
|
else
|
868
892
|
res.each_row do |res_row, row|
|
869
|
-
obj = klass.og_allocate(res_row)
|
893
|
+
obj = klass.og_allocate(res_row, row)
|
870
894
|
obj.og_read(res_row, row)
|
871
895
|
read_join_relations(obj, res_row, row, join_relations) if join_relations
|
872
896
|
objects << obj
|
data/lib/og/store/sqlite.rb
CHANGED
@@ -184,7 +184,7 @@ private
|
|
184
184
|
|
185
185
|
def eval_og_insert(klass)
|
186
186
|
pk = klass.primary_key.first
|
187
|
-
props = klass.properties
|
187
|
+
props = klass.properties.dup
|
188
188
|
values = props.collect { |p| write_prop(p) }.join(',')
|
189
189
|
|
190
190
|
if klass.metadata.superclass or klass.metadata.subclasses
|
data/test/og/tc_inheritance.rb
CHANGED
@@ -41,13 +41,22 @@ class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all
|
|
41
41
|
:name => :test
|
42
42
|
)
|
43
43
|
=end
|
44
|
-
|
44
|
+
=begin
|
45
45
|
@og = Og.setup(
|
46
46
|
:destroy => true,
|
47
47
|
:store => :sqlite,
|
48
48
|
:name => 'test'
|
49
49
|
)
|
50
|
-
|
50
|
+
=end
|
51
|
+
#=begin
|
52
|
+
@og = Og.setup(
|
53
|
+
:destroy => true,
|
54
|
+
:store => :psql,
|
55
|
+
:name => 'test',
|
56
|
+
:user => 'postgres',
|
57
|
+
:password => 'navelrulez'
|
58
|
+
)
|
59
|
+
#=end
|
51
60
|
=begin
|
52
61
|
@og = Og.setup(
|
53
62
|
:destroy => true,
|
data/test/og/tc_relation.rb
CHANGED
@@ -46,7 +46,7 @@ class TestCaseOgRelation < Test::Unit::TestCase # :nodoc: all
|
|
46
46
|
og = Og.setup(:store => :memory, :name => 'test')
|
47
47
|
og.manage_classes
|
48
48
|
|
49
|
-
# test refers_to accessor is correctly updated
|
49
|
+
# test refers_to accessor is correctly updated
|
50
50
|
u = User.create("George")
|
51
51
|
a = Article.create("Og is a good thing!")
|
52
52
|
assert_equal(nil, a.active_user)
|
@@ -60,7 +60,20 @@ class TestCaseOgRelation < Test::Unit::TestCase # :nodoc: all
|
|
60
60
|
a.active_user = u2
|
61
61
|
a.save!
|
62
62
|
assert_equal(u2.oid, a.active_user_oid)
|
63
|
+
|
64
|
+
# Note! Og doesn't automatically reload object referred by active_user
|
65
|
+
# so this won't equal.
|
66
|
+
assert_not_equal(u2.object_id, a.active_user.object_id)
|
67
|
+
|
68
|
+
# Even forced reload won't help here as it won't reload relations.
|
69
|
+
a.reload
|
70
|
+
assert_not_equal(u2.object_id, a.active_user.object_id)
|
71
|
+
|
72
|
+
# But forcing enchanted accessor to reload in refers_to.rb helps!
|
73
|
+
a.active_user(true)
|
63
74
|
assert_equal(u2.object_id, a.active_user.object_id)
|
75
|
+
# and just to be sure oids are still correct
|
76
|
+
assert_equal(u2.oid, a.active_user_oid)
|
64
77
|
end
|
65
78
|
end
|
66
79
|
|
data/test/og/tc_store.rb
CHANGED
@@ -41,6 +41,10 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
class NewArticle < Article
|
45
|
+
property :more_text, String
|
46
|
+
end
|
47
|
+
|
44
48
|
class Comment
|
45
49
|
property :body, String
|
46
50
|
property :hits, Fixnum
|
@@ -85,7 +89,7 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
85
89
|
# conversions_test
|
86
90
|
end
|
87
91
|
=end
|
88
|
-
|
92
|
+
=begin
|
89
93
|
def test_psql
|
90
94
|
@og = Og.setup(
|
91
95
|
:destroy => true,
|
@@ -98,7 +102,7 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
98
102
|
features_test
|
99
103
|
conversions_test
|
100
104
|
end
|
101
|
-
|
105
|
+
=end
|
102
106
|
=begin
|
103
107
|
def test_mysql
|
104
108
|
@og = Og.setup(
|
@@ -113,7 +117,7 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
113
117
|
# conversions_test
|
114
118
|
end
|
115
119
|
=end
|
116
|
-
|
120
|
+
#=begin
|
117
121
|
def test_sqlite
|
118
122
|
@og = Og.setup(
|
119
123
|
:destroy => true,
|
@@ -123,7 +127,7 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
123
127
|
features_test
|
124
128
|
conversions_test
|
125
129
|
end
|
126
|
-
|
130
|
+
#=end
|
127
131
|
=begin
|
128
132
|
def test_memory
|
129
133
|
@og = Og.setup(
|
@@ -229,13 +233,13 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
229
233
|
|
230
234
|
# update_properties
|
231
235
|
|
232
|
-
assert_equal 4, Comment.
|
236
|
+
assert_equal 4, Comment.update('@hits = @hits + 1')
|
233
237
|
cc = Comment[1]
|
234
238
|
assert_equal 1, cc.hits
|
235
|
-
Comment.
|
239
|
+
Comment.update('@hits = @hits + 1', :condition => 'oid = 1')
|
236
240
|
cc.reload
|
237
241
|
assert_equal 2, cc.hits
|
238
|
-
cc.
|
242
|
+
cc.update_by_sql '@hits = @hits + 1'
|
239
243
|
cc.reload
|
240
244
|
assert_equal 3, cc.hits
|
241
245
|
|
@@ -249,7 +253,7 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
249
253
|
|
250
254
|
cc.hits += 1
|
251
255
|
cc.body = 'Wow!'
|
252
|
-
cc.
|
256
|
+
cc.update_properties :hits, :body
|
253
257
|
cc.reload
|
254
258
|
assert_equal 'Wow!', cc.body
|
255
259
|
|
@@ -314,18 +318,26 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
314
318
|
a.categories << c1
|
315
319
|
a.save
|
316
320
|
a.categories << c2
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
321
|
+
a.save
|
322
|
+
|
323
|
+
assert_equal 2, a.categories.size
|
324
|
+
|
325
|
+
a = Article.find_by_body('Hello').first
|
326
|
+
assert_equal 2, a.categories.size
|
327
|
+
assert_equal 'News', a.categories[0].title
|
328
|
+
|
329
|
+
c = Category.find_by_title('News')
|
330
|
+
assert_equal 1, c.articles.size
|
324
331
|
|
325
|
-
c = Category.find_by_title('News')
|
326
|
-
assert_equal 1, c.articles.size
|
327
332
|
|
328
|
-
|
333
|
+
# bug: extended class and many_to_many.
|
334
|
+
|
335
|
+
na = NewArticle.create('Bug')
|
336
|
+
na.categories << c1
|
337
|
+
na.categories << c2
|
338
|
+
assert_equal 2, na.categories.size
|
339
|
+
|
340
|
+
# bug: self join bug.
|
329
341
|
|
330
342
|
b1 = Bugger.create
|
331
343
|
b2 = Bugger.create
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: og
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.21.
|
7
|
-
date: 2005-07-
|
6
|
+
version: 0.21.2
|
7
|
+
date: 2005-07-28 00:00:00 +03:00
|
8
8
|
summary: Og (ObjectGraph)
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -124,5 +124,5 @@ dependencies:
|
|
124
124
|
-
|
125
125
|
- "="
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version: 0.21.
|
127
|
+
version: 0.21.2
|
128
128
|
version:
|