[Nitro] Og 1-n relation alias bug

Kristof Jozsa dyn at ond.vein.hu
Sat Aug 13 19:52:05 EDT 2005


Hello guys,

I think I've got something real bad for you this time. Consider the
following testcase:

------
#!/usr/bin/ruby -rubygems
$DBG = true

require 'og'
require 'test/unit'

class Book
  include Og::EntityMixin
  property :title
  belongs_to :owner, Person
end

class Person
  include Og::EntityMixin
  property :name, Og::VarChar(128)
  has_many :books, Book
end

class TestOg < Test::Unit::TestCase
  include Og

  def test_basic
    book = Book.create
    person = Person.create
    person.books << book    # blows here
  end


  def setup
    Og.table_prefix = nil
    og = Og.setup(:store => :memory, :name => 'test')
  end
end
------

At the marked line the relationships blows with the message:
NoMethodError: undefined method `person_oid=' for #<Book:0xb7b38600 @oid=1>

Now I gave it some time and try to dig down to the root of the problem
to a be bit more help now just whine here ;) Unfortunately all I could
find out is that around that has_many.rb uses a slighly naive-looking
approach at setting up the collection's options. 'foreign_name' is not
set at all so foreign_key is made up of owner_singular_name which does
not care much about the alias set up for the collection. No wonder the
whole thing crashes then on the enchanted add_stuff method :(

As a side note, eg. for refers_to the foreign_key is filled according to
my added logs but I still could not find where it was set from, some
black magic might be happening here.. :)


George, while you're into it, please try to delete any of the plain
properties from the classes defined above and rerun the test. It dies
for me with:

NoMethodError: undefined method `store' for nil:NilClass

The very same happens when trying to define the Og::Entity superclass
instead of the mixin..

cheers,

Kristof



More information about the Nitro-general mailing list