The problem was that the block was being called before the class name was set, 
so the has n association was not seeing the its class name. I fixed it by 
setting the class name before calling the block:

def create_class(class_name, &block)
  klass = Class.new
  Object.const_set class_name, klass
  klass.class_exec &block
end

On Jan 19, 2011, at 12:50 PM, RipTheJacker wrote:

> Oh...and the Object.full_const_set is added by DM. I used it just in
> case there are modules nested.
> 
> On Jan 19, 12:49 pm, RipTheJacker <[email protected]> wrote:
>> I believe that anonymous classes work differently in 1.9.2, so come
>> class variables DM might need may not be available when you are
>> creating classes in that fashion. However, you can simplify that
>> method so that it works in both:
>> 
>> def create_class(class_name, &block)
>>   Object.full_const_set class_name, DataMapper::Model.new(&block)
>> end
>> 
>> That way, you also can get rid of the: 'include DataMapper::Resource'
>> 
>> so:http://pastie.org/1478183
>> 
>> On Jan 19, 12:16 am, Joshua Griffith <[email protected]> wrote:
>> 
>> 
>> 
>>> Hello,
>> 
>>> When dynamically creating resource classes, I'm getting the following
>>> error:
>>> ruby-1.9.2-p136/gems/dm-core-1.0.2/lib/dm-core/associations/
>>> relationship.rb:494:in `initialize_object_ivar': parent_model does not
>>> respond to #to_str or #name (ArgumentError)
>> 
>>> This error does not get thrown when using ruby 1.8.7. Can anyone
>>> assist me in tracking down the problem? Here is the test 
>>> case:http://pastie.org/1476312
>> 
>>> Thanks,
>> 
>>> Joshua
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/datamapper?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to