[Nitro] in... vain...
Emmanuel Piperakis
epiperak at softlab.ece.ntua.gr
Tue Dec 13 01:10:46 EST 2005
Dear list,
I have posted the same problem in the past, and I have been reassured that
in 0.25 it would be fixed... here is a bit of code that illustrates the
problem...
1 require 'rubygems'
2 require 'og'
3
4 # Model
5 class Foo
6 property :name, String
7 has_many Bar
8 end
9
10 class Bar
11 property :name, String
12 belongs_to Foo
13 has_many Foobar
14 end
15
16 class Foobar
17 property :name, String
18 belongs_to Bar
19 end
20
21 # Init
22 Og.setup(
23 :destroy => true,
24 :store => :sqlite,
25 :name => 'test'
26 )
27
28 # preparing Tests
29
30 2.times{|i|
31 foo = Foo.new
32 foo.name = "foo #{i}"
33 foo.save
34 }
35 Foo.all.length
36
37 3.times{|i|
38 bar = Bar.new
39 bar.name = "bar #{i}"
40 bar.save
41 }
42 Bar.all.length
43
44 6.times{|i|
45 foobar = Foobar.new
46 foobar.name = "foobar #{i}"
47 foobar.save
48 }
49 Foobar.all.length
50
51 foo1 = Foo[1]
52 bar1 = Bar[1]
53 bar1.add_foobar Foobar[1]
54 bar1.add_foobar Foobar[2]
55 bar1.add_foobar Foobar[3]
56 bar1.save
57 foo1.add_bar bar1
58 foo1.save
59
60 foo2 = Foo[2]
61 bar2 = Bar[2]
62 bar3 = Bar[3]
63 bar2.add_foobar Foobar[4]
64 bar3.add_foobar Foobar[5]
65 bar3.add_foobar Foobar[6]
66 bar2.save
67 bar3.save
68 foo2.add_bar bar2
69 foo2.add_bar bar3
70 foo2.save
71
72 # this work...
73 ar = Array.new
74 foo1.bars.each {|ii|
75 ar.push(ii.foobars)
76 }
77
78 ar.flatten!
79 ar.size
80
81 # next line should work, but it does not
82 foo_foobars = foo1.bars.foobars
83 foo_foobars.class
even though foo1.bars is a collection foo1.bars.foobars does not work,
nor foo1.bars.find_foobars
G?
Emmanouil Piperakis (epiperak at cs.ntua.gr)
{To explore is Human, to Create is Devine,
To teach is Primal, to Rule is Sin}
More information about the Nitro-general
mailing list