#725 ✓resolved
dmilith

BUG with many to many association

Reported by dmilith | December 21st, 2008 @ 09:08 PM

class Domain
  include DataMapper::Resource

  property  :id,        Serial,  :index => true
  property  :name,      String,     :nullable => false,  :default => "drakor.eu"
  property  :owner_id,  Integer,  :index => true, :default => 1
  property :created_at, DateTime
  property :created_on, Date
  property :updated_at, DateTime
  property :updated_on, Date

  has n, :usage_permissions
  has n, :users, :through => :usage_permissions, :mutable => true # workaround XXX http://datamapper.lighthouseapp.com/projects/20609/tickets/485-has-n-through-does-not-allow-saving-of-model
  has n, :subdomains
  belongs_to :owner, :class_name => "User"
end


class UsagePermission
  include DataMapper::Resource

    property :id,                              Serial,  :index => true
    property :available_subdomains_count,   Integer
    property :domain_id,                      Integer,  :index => true
    property :user_id,                        Integer,  :index => true
    property :created_at, DateTime
    property :created_on, Date
    property :updated_at, DateTime
    property :updated_on, Date

    belongs_to :user
    belongs_to :domain
end


class User
  include DataMapper::Resource

  has n, :usage_permissions
  has n, :domains, :through => :usage_permissions, :mutable => true # workaround XXX http://datamapper.lighthouseapp.com/projects/20609/tickets/485-has-n-through-does-not-allow-saving-of-model
  has n, :subdomains
  has n, :ports
  has n, :memory_usage_records

# ...
end


@user = User.first # ok

@domain = Domain.new # ok

@domain.owner = @user # ok but why the hell it's creating user_id and owner_id ? I don't have such column.. anyway..

@domain.valid? # true

@domain.users << @user # ok!

@domain.valid? # true

@domain.save # BIG FAT BUG:

NoMethodError: undefined method attach_parent' for #<DataMapper::Associations::RelationshipChain:0x7fc73de0ddd0> from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/one_to_many.rb:302:insave_resource'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/relationship.rb:172:in with_repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/support/kernel.rb:6:inrepository'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core.rb:181:in repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/repository.rb:44:inscope'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core.rb:181:in repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/support/kernel.rb:6:inrepository'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/relationship.rb:172:in with_repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/one_to_many.rb:298:insave_resource'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/one_to_many.rb:210:in save' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/lazy_array.rb:391:ineach'
from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/lazy_array.rb:391:in send' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/lazy_array.rb:391:inmethod_missing'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/collection.rb:638:in method_missing' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/one_to_many.rb:309:insend'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/one_to_many.rb:309:in method_missing' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/associations/one_to_many.rb:210:insave'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/resource.rb:286:in hookable__save_nan_before_advised' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/resource.rb:286:ineach'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.8/lib/dm-core/resource.rb:286:in hookable__save_nan_before_advised' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:294:insave'
from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:292:in catch' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:292:insave'
from (irb):10

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

Pages