This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a test case for a DataMapper bug handling a relation from a table to itself. | |
# ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0] | |
# sqlite 3.6.22 | |
# Mac OS X 10.6.3 | |
require 'rubygems' | |
require 'dm-core' #0.9.12 | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
class Relation | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :contacter, 'User' | |
belongs_to :contact, 'User' | |
end | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :url, String, :required => true, :unique => true | |
has n, :relations, :child_key => [:contacter_id] | |
has n, :contacts, :through => :relations, :model => 'User' | |
def contactWithURL (url) | |
return self.contacts.first(:url => url) | |
end | |
end | |
DataMapper.auto_migrate! | |
user = User.create({:url => 'http://example.com'}) | |
user.contactWithURL('http://rubylang.org') | |
# Result: | |
# | |
#~ ambiguous column name: users.id (code: 1, sql state: , query: SELECT "users"."id", "users"."local_name", | |
# "users"."url" FROM "users" INNER JOIN "relations" ON "users"."id" = "relations"."contact_id" INNER JOIN | |
# "users" ON "relations"."contacter_id" = "users"."id" WHERE ("users"."url" = 'http://rubylang.org' AND | |
# "relations"."contacter_id" = 1) GROUP BY "users"."id", "users"."local_name", "users"."url" ORDER BY | |
# "users"."id" LIMIT 1, uri: sqlite3://:memory:) | |
# | |
# DataObjects::SyntaxError: ambiguous column name: users.id | |
# | |
# method execute_reader in data_objects_adapter.rb at line 140 | |
# method read in data_objects_adapter.rb at line 140 | |
# method with_connection in data_objects_adapter.rb at line 269 | |
# method read in data_objects_adapter.rb at line 136 | |
# method read in repository.rb at line 145 | |
# method lazy_load in collection.rb at line 1111 | |
# method lazy_load in one_to_many.rb at line 270 | |
# method to_a in lazy_array.rb at line 275 | |
# method first in collection.rb at line 275 | |
# method contactWithURL in _datamapper_bug.rb at line 32 | |
# at top level |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment