
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:in
save_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:in
repository'
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:in
scope'
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:in
repository'
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:in
save_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:in
each'
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:in
method_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:in
send'
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:in
save'
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:in
each'
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:in
save'
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:in
save'
from (irb):10
Comments and changes to this ticket
-
Dan Kubb (dkubb) January 8th, 2009 @ 05:17 AM
- State changed from unconfirmed to accepted
- Assigned user set to Dan Kubb (dkubb)
-
-
Justin Smestad February 23rd, 2009 @ 04:37 PM
As far as I can tell this is still occuring in dm-next. One thing to note is if @user = nil when the << occurs, the save will go through fine. So the case is most likely isolated to the attachment mechanism.
-
-
Dan Kubb (dkubb) May 15th, 2009 @ 06:49 PM
- State changed from accepted to resolved
This appears to be working on the dm-core/next branch. I am marking as resolved.
Please confirm if the problem is fixed for you, and if not I will re-open this ticket.
-
Dan Kubb (dkubb) May 15th, 2009 @ 06:51 PM
Attached is the script I used to confirm the issue is fixed.
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »