views:

71

answers:

1

I am stuck in this error for quite sometime now and have hit a dead end.

I get this totally unhelpful error

can't dup NilClass

This is the situation.

I have one class which is in a relationship with another. Say

 class Parent
 end

 class Child < Parent
    unloadable
     :has_many :parents, :foreign_key => "child"
 end

The error does not occur the first time it is accessed. It occurs the second time the child is accessed.

What is exactly causing this error and is there a solution?

I referred the following link but it doesn't help

Update

I found this

But it suggests the same again. But i do have a module in my lib. It Has nothing to do with the model though.

A: 

Why are you marking the Child as unloadable? Is there a good reason for this? if not, I'd remove.

Rails API says "Unloadable constants are removed each time dependencies are cleared."

Does the error happen when you change it to:

class Child < Parent
  has_many :parents, :foreign_key => "child"
end

And, I may be overstepping, but this seems more standard:

class Child
  belongs_to :parent
end

class Parent
  has_many :children, :dependent=>:destroy
end
Jesse Wolgamott
but http://rails.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html says not to use :destroy when using :has_many.?
ZX12R
I believe it means don't have "belongs_to :parent, :dependent=>:destroy" -- in that case, if a parent has 4 children, and you destroy a child, then the child and the parent would be destroyed, but the other 3 child remain orphans.
Jesse Wolgamott