[Nitro] Possible BUG in lib/og/relation/has_many.rb (and possible fix)

Aidan Rogers aidan at yoyo.org
Mon Jan 30 01:36:00 EST 2006


Hi Bryan,

The collection has been and still is YAMLised as a Ruby object - that  
means I can serialise/de-serialise using YAML and the correct object  
type gets created.  All that I've done is modify the member_class  
variable so that it YAMLises as a string.  I've modified the  
behaviour of Og::Collection to understand that member_class is now  
initialised as a String as opposed to a Class.  This does not change  
the behaviour of Og::Collection as far as Og is concerned (it's all  
encapsulated), but when YAML kicks in, it now works.  Here's a pseudo- 
unit test (you'll need to ensure Foo and Bar are managed by Og).   
Note, I've not tested this verbatim :-)

require 'og'

class Foo
   property :foo_prop, String
   has_many :bars, Bar
end

class Bar
   property :bar_prop, String
   belongs_to :foo, Foo
end

bar = Bar.create
foo = Foo.create
foo.bars << bar
assert_equal foo, YAML::load( foo.to_yaml )

This should barf.  Apply my fix, it should work.

Aidan

On 30/01/2006, at 4:50 PM, Bryan Soto wrote:

> Hi Aidan,
>
> You've been busy :)
>
> I don't know much about Yaml to be honest. So with this patch, does  
> the collection actually get represented properly as a list or other  
> collection? Although, I suppose I should just sit down and try it  
> out. ;)
>
> Bryan
>
>
> On 1/29/06, Aidan Rogers <aidan at yoyo.org> wrote: Eh, got fed up and  
> went with option two - it was only a few lines of
> code in the end.  I've submitted the patch using darcs, but I've
> blogged it for those who might need it.
>
> http://www.infurious.com/blogs/index.php/aidan/2006/01/29/
> yaml_bug_in_og_0_27_0
>



More information about the Nitro-general mailing list