I've just upgraded from dm-0.9.11 to 0.10.1, and I am having some  
troubles. I've tracked it down to the relationship between these two  
models:

        http://pastie.org/644626 (also, see below)

Status belongs to collector, and collector has many statuses.  
Additionally, status belongs_to one status in particular called  
"seed". So there is a circular relationship going on. When I run my  
specs, it goes into an infinite loop. You can get the gist of it from  
this excerpt:

        /Library/Ruby/Gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb: 
569:in `save_parents'
        /Library/Ruby/Gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb: 
148:in `all?'
        /Library/Ruby/Gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb: 
567:in `each'
        /Library/Ruby/Gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb: 
567:in `all?'
        /Library/Ruby/Gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb: 
567:in `save_parents'
        /Library/Ruby/Gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb: 
343:in `save'
        /Library/Ruby/Gems/1.8/gems/dm-validations-0.10.1/lib/dm- 
validations.rb:48:in `save'
        /Library/Ruby/Gems/1.8/gems/dm-validations-0.10.1/lib/dm-validations/ 
support/context.rb:29:in `validation_context'
        /Library/Ruby/Gems/1.8/gems/dm-validations-0.10.1/lib/dm- 
validations.rb:48:in `save'
        ./spec/collector_spec.rb:73:

It seems that when collector saves its parents, it fetches the "seed"  
and saves it. Then save_parents is called on the seed, which points  
back to the original collector, and so on...

This wasn't a problem in previous versions of DataMapper. Do I need to  
change anything in the relationships between those two models?

Thanks in advance.
Drew

----------------------------------------------------------------

class Status
   include DataMapper::Resource

   property :id,                Serial
   property :text,              String,   :length => 0..255
   property :collector_id,      Integer

   belongs_to :collector

end

class Collector
   include DataMapper::Resource

   property :id,               Serial
   property :name,             String, :length => 0..255
   property :status_id,        Integer

   belongs_to :seed, :model => 'Status', :child_key => [:status_id]
   has n, :statuses

end


--~--~---------~--~----~------------~-------~--~----~
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