
Associations throw error with two level deep STI
Reported by Sindre Aarsaether | May 4th, 2009 @ 09:40 AM
Script that displays the bug: http://gist.github.com/106493
Pasted here to:
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default,
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:database => 'dm_core_test',
:encoding => 'utf8'
)
DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, :debug)
class Person
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
property :name, String
has n, :articles
end
class Author < Person
end
class Journalist < Author
end
class Article
include DataMapper::Resource
property :id, Serial
property :body, Text
belongs_to :author
end
Author.auto_migrate!
Article.auto_migrate!
a = Author.create(:name => 'dkubb')
a.articles.build(:body => "Tralala")
a.articles.build(:body => "Trololo")
a.save
a2 = Journalist.create(:name => 'somebee')
a2.articles.build(:body => "Test")
a2.articles.build(:body => "Tust")
a2.articles.build(:body => "Tast")
a2.save
puts Journalist.first.articles.inspect
# >
# /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:778:in `assert_valid_conditions': condition nil of an unsupported object NilClass (ArgumentError)
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:749:in `each'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:749:in `assert_valid_conditions'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:668:in `assert_valid_options'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:658:in `each'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:658:in `assert_valid_options'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:587:in `initialize'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:37:in `new'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:37:in `query_for'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:54:in `collection_for'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:141:in `lazy_load'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:70:in `get'
# from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:111:in `articles'
# from stubugs-2.rb:52
UPDATE: Does not need to be two levels deep STI. Happens anyway.
Comments and changes to this ticket
-
Sindre Aarsaether May 4th, 2009 @ 10:10 AM
- Title changed from Associations throw error with STI to Associations throw error with two level deep STI
Hmm, this has something to do with the #resverse stuff for relationships? It works if you add every STI-relationship specifically to Article.. Like:
class Article include DataMapper::Resource property :id, Serial property :body, Text belongs_to :person belongs_to :author , :child_key => [:person_id] belongs_to :journalist, :child_key => [:person_id] end
But this is obviously not intuitive, nor correct :)
-
Dan Kubb (dkubb) May 5th, 2009 @ 03:11 AM
- Assigned user set to Dan Kubb (dkubb)
- State changed from unconfirmed to confirmed
I've fixed this in the dm-core/next branch. Would you mind verifying?
-
Sindre Aarsaether May 5th, 2009 @ 03:19 AM
I can confirm that this is now fixed in dm-core/next. Thanks!
-
Dan Kubb (dkubb) May 15th, 2009 @ 10:59 PM
- State changed from confirmed to resolved
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 »