This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
multiple query paths map to the first child model. #52
Open
Description
I noticed when using multiple query paths with a model that had multiple belongs_to relationships, the other query paths would map to the first child model.
gem 'dm-core', '~> 1.0.2'
gem 'dm-migrations', '~> 1.0.2'
require 'dm-core'
require 'dm-migrations'
class HostName
include DataMapper::Resource
include DataMapper::Migrations
property :id, Serial
property :name, String
has 0..n, :urls
end
class Port
include DataMapper::Resource
include DataMapper::Migrations
property :id, Serial
property :number, Integer
has 0..n, :urls
end
class Url
include DataMapper::Resource
include DataMapper::Migrations
property :id, Serial
belongs_to :host_name
belongs_to :port
property :path, String
end
DataMapper.setup(:default, 'sqlite3:dm_bug.db')
DataMapper.auto_migrate!
url = Url.create(
:host_name => {:name => 'example.com'},
:port => {:number => 80},
:path => '/index.html'
)
# works
puts (
Url.all('host_name.name' => 'example.com') &
Url.all('port.number' => 80)
).first
# fails
puts Url.first(
'host_name.name' => 'example.com',
'port.number' => 80
)
#<Url:0x00000001c522d0>
/home/hal/.rvm/gems/ruby-1.9.2-p136/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:142:in `execute_reader': no such column: host_names.port_id (DataObjects::SyntaxError)
from /home/hal/.rvm/gems/ruby-1.9.2-p136/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:142:in `block in read'
from /home/hal/.rvm/gems/ruby-1.9.2-p136/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:260:in `with_connection'
from /home/hal/.rvm/gems/ruby-1.9.2-p136/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:138:in `read'
from /home/hal/.rvm/gems/ruby-1.9.2-p136/gems/dm-core-1.0.2/lib/dm-core/repository.rb:162:in `read'
from /home/hal/.rvm/gems/ruby-1.9.2-p136/gems/dm-core-1.0.2/lib/dm-core/model.rb:379:in `first'
from dm_bug.rb:64:in `<main>'
Created by Postmodern - 2011-01-05 02:30:47 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1467