#1065 ✓resolved
Mauricio Eduardo Szabo

Self-Referential has many doesn't works.

Reported by Mauricio Eduardo Szabo | September 30th, 2009 @ 10:21 AM | in 0.10.2

Well, I just followed the site's tutorial on Self-Referential Has, and belongs to, many, but when I try to auto-migrate the column, it gives me an error. The code I'm trying to use is:

require 'dm-core'

class User
  include DataMapper::Resource

  property :id, Serial
  property :name, String, :nullable => false

  has n, :friended_users
  has n, :friends, :through => :friended_users, :class_name => "User",
                   :child_key => [:user_id]
  has n, :friended_by, :through => :friended_users, :class_name => "User",
                       :remote_name => :user, :child_key => [:friend_id]
end

class FriendedUser
  include DataMapper::Resource

  property :user_id, Integer, :key => true
  property :friend_id, Integer, :key => true

  belongs_to :user, :child_key => [:user_id]
  belongs_to :friend, :class_name => "User", :child_key => [:friend_id]
end

DataMapper.setup :default, 'sqlite3::memory:'
DataMapper.auto_migrate!

and the error:

    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/property_set.rb:169:in `map'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/property_set.rb:169:in `initialize'                          
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/many_to_many.rb:23:in `new'                     
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/many_to_many.rb:23:in `child_key'               
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:695:in `assert_valid'                               
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:694:in `each_value'                                 
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:694:in `assert_valid'                               
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:693:in `each_value'                                 
     ... 6 levels...
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:48:in `repository_execute'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:36:in `auto_migrate_down!'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:21:in `auto_migrate!'
    from /tmp/test.rb:27

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Attachments

Referenced by

Pages