Property mappings for multiple repositories doesn't work
Reported by Mark Bates | August 22nd, 2008 @ 12:12 PM
If you are trying to map to multiple repositories in a single model, the default repository works fine, but If you call the other repo it tries to look up ALL the columns mapped for the model, not just the ones for that repository.
class Passport
include DataMapper::Resource
storage_names[:hls] = "tbl_pssptz"
property :id, Integer, :key => true
property :country_code, String, :nullable => false
property :expiration_date, Date, :nullable => false
repository(:hls) do
property :id, String, :size => 11, :key => true, :field => "pid"
property :person_id, Integer, :field => "peopleid"
property :country_code, Integer
property :expiration_date, Date, :field => "expdate"
end
end
#--
repository(:hls) { puts Passport.all }
DEBUG: [2008-08-21 21:26:52] SELECT `id`, `country_code`, `expiration_date`, `id`, `person_id`, `country_code`, `expiration_date` FROM `tbl_pssptz` ORDER BY `id`
DEBUG: [2008-08-21 21:26:52] Unknown column 'id' in 'field list' (mysql_error_code=0001)
DEBUG: [2008-08-21 21:26:52] #<DataObjects::Mysql::Connection:0x2626784 @using_socket=false, @__allocated_in_pool=Thu Aug 21 21:26:52 -0400 2008, @concrete_command=DataObjects::Mysql::Command, @__pool=#<Extlib::Pooling::Pool<DataObjects::Mysql::Connection> available=0 reserved_count=1>, @connection=#<Object:0x2626658>, @uri=#<Addressable::URI:0x12628ce URI:mysql://root@localhost/hls_db>>
Comments and changes to this ticket
-
Bernerd Schaefer August 22nd, 2008 @ 01:34 PM
- → State changed from new to resolved
Okay. This is fixed now on edge (6278e45). Thanks for finding this.
-
Mark Bates August 22nd, 2008 @ 01:42 PM
Close, very close, but it's still trying to order by the non-existent 'id' column instead of the 'pid' column, which is the key.
SELECT "pid", "country_code", "expdate", "peopleid" FROM "tbl_pssptz" ORDER BY "id" -
Mark Bates September 7th, 2008 @ 11:07 AM
This ticket needs to be reopened as it's still not working right. See my last entry for details.
-
Mark Bates September 7th, 2008 @ 11:11 AM
There are other issues with this as well. I have the following two models:
class Passport include DataMapper::Resource storage_names[:hls] = "tbl_pssptz" repository(:default) do property :id, Integer, :key => true property :country_code, String, :nullable => false property :expiration_date, Date, :nullable => false belongs_to :passenger end repository(:hls) do property :id, String, :size => 11, :key => true property :passenger_id, Integer, :field => "peopleid" property :country_id, Integer, :field => "country_code" property :expiration_date, Date, :field => "expdate" belongs_to :country belongs_to :passenger end end class Passenger include DataMapper::Resource storage_names[:hls] = "tbl_people" repository(:default) do property :id, Serial property :first_name, String property :last_name, String property :notes, Text, :nullable => true, :lazy => false has 1, :passport has n, :tickets has n, :flights, :through => :tickets has n, :bookings, :through => :tickets end repository(:hls) do property :full_name, LegacyName, :field => "name_ENC" property :eye_color, String, :nullable => true, :lazy => :looks property :weight, Integer, :nullable => true, :lazy => :looks property :notes, Text, :nullable => true, :lazy => :all property :notes_2, Text, :nullable => true, :lazy => [:all, :extras] property :notes_3, Text, :nullable => true, :lazy => [:all, :extras] end endIf I make a call like this:
repository(:hls) {puts Passport.first.passenger.inspect}I expect to get back the Passenger associated with the Passport. Because this is all wrapped in a repo block I would expect them to get called from the hls dbs. Instead I get these sql queries, followed by an error:
DEBUG: [2008-09-07 12:05:07] SELECT `id`, `country_code`, `expdate`, `peopleid`, `country_code` FROM `tbl_pssptz` ORDER BY `id` LIMIT 1 DEBUG: [2008-09-07 12:05:07] SELECT `id`, `first_name`, `last_name`, `name_ENC` FROM `tbl_people` WHERE `id` IN (1) ORDER BY `id` DEBUG: [2008-09-07 12:05:07] Unknown column 'first_name' in 'field list' (mysql_error_code=0001) DEBUG: [2008-09-07 12:05:07] #<DataObjects::Mysql::Connection:0x2275810 @concrete_command=DataObjects::Mysql::Command, @__pool=#<Extlib::Pooling::Pool<DataObjects::Mysql::Connection> available=0 reserved_count=1>, @uri=#<Addressable::URI:0x11541d0 URI:mysql://root@localhost/hls_db>, @connection=#<Object:0x22756e4>, @__allocated_in_pool=Sun Sep 07 12:05:07 -0400 2008, @using_socket=false> ERROR: [2008-09-07 12:05:07] Caught MysqlError: Unknown column 'first_name' in 'field list' (mysql_error_code=0001) /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:45:in `execute_reader' /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:45:in `read_many' /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:168:in `with_connection' /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:40:in `read_many' /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.5/lib/extlib/lazy_array.rb:89:in `[]' /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.5/lib/extlib/lazy_array.rb:89:in `lazy_load' /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.5/lib/extlib/lazy_array.rb:23:in `empty?' MysqlError: Unknown column 'first_name' in 'field list' (mysql_error_code=0001) from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:45:in `execute_reader' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:45:in `read_many' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:168:in `with_connection' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/adapters/data_objects_adapter.rb:40:in `read_many' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.5/lib/extlib/lazy_array.rb:89:in `[]' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.5/lib/extlib/lazy_array.rb:89:in `lazy_load' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.5/lib/extlib/lazy_array.rb:23:in `empty?' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/associations/relationship.rb:149:in `get_parent' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/repository.rb:44:in `scope' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core.rb:190:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/support/kernel.rb:5:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/associations/relationship.rb:168:in `with_repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/associations/relationship.rb:131:in `get_parent' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/associations/many_to_one.rb:98:in `parent' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/associations/many_to_one.rb:102:in `method_missing' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/associations/many_to_one.rb:17:in `passenger' from (irb):1 from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/repository.rb:44:in `scope' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core.rb:190:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.5/lib/dm-core/support/kernel.rb:5:in `repository' -
Adam French September 7th, 2008 @ 11:44 AM
- → State changed from resolved to open
-
Bernerd Schaefer September 11th, 2008 @ 09:59 AM
Mark -- Just wanted to let you know I'm taking a look at this one again today.
-
-
Bernerd Schaefer September 11th, 2008 @ 12:03 PM
Okay, Mark. I think I've fixed this.
Take a look at http://github.com/sam/dm-core/co..., and give it a spin, please.
Bernerd
-
Mark Bates September 13th, 2008 @ 08:30 PM
Sorry Bernerd, it doesn't seem to work, i'm still getting the same errors:
repository(:hls) {puts Passport.first.passenger.inspect} DEBUG: [2008-09-13 21:28:34] SELECT `id`, `country_code`, `expdate`, `peopleid`, `country_code` FROM `tbl_pssptz` ORDER BY `id` LIMIT 1 DEBUG: [2008-09-13 21:28:34] SELECT `id`, `first_name`, `last_name`, `name_ENC` FROM `tbl_people` WHERE (`id` IN (1)) ORDER BY `id` DEBUG: [2008-09-13 21:28:34] Unknown column 'first_name' in 'field list' (mysql_error_code=0001) DEBUG: [2008-09-13 21:28:34] #<DataObjects::Mysql::Connection:0x2294468 @concrete_command=DataObjects::Mysql::Command, @__allocated_in_pool=Sat Sep 13 21:28:34 -0400 2008, @__pool=#<Extlib::Pooling::Pool<DataObjects::Mysql::Connection> available=0 used=1 size=8>, @uri=#<struct DataObjects::URI scheme="mysql", user="root", password=nil, host="localhost", port=nil, specified_port=nil, path="/hls_db", query=nil, fragment=nil>, @connection=#<Object:0x2294378>, @using_socket=false> ERROR: [2008-09-13 21:28:34] Caught MysqlError: Unknown column 'first_name' in 'field list' (mysql_error_code=0001) /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:48:in `execute_reader' /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:48:in `read_many' /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:171:in `with_connection' /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:40:in `read_many' /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.7/lib/extlib/lazy_array.rb:89:in `[]' /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.7/lib/extlib/lazy_array.rb:89:in `lazy_load' /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.7/lib/extlib/lazy_array.rb:23:in `empty?' MysqlError: Unknown column 'first_name' in 'field list' (mysql_error_code=0001) from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:48:in `execute_reader' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:48:in `read_many' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:171:in `with_connection' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:40:in `read_many' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.7/lib/extlib/lazy_array.rb:89:in `[]' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.7/lib/extlib/lazy_array.rb:89:in `lazy_load' from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.7/lib/extlib/lazy_array.rb:23:in `empty?' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/relationship.rb:149:in `get_parent' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/repository.rb:44:in `scope' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core.rb:191:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/support/kernel.rb:5:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/relationship.rb:167:in `with_repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/relationship.rb:131:in `get_parent' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/many_to_one.rb:98:in `parent' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/many_to_one.rb:102:in `method_missing' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/many_to_one.rb:17:in `passenger' from (irb):1 from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/repository.rb:44:in `scope' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core.rb:191:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/support/kernel.rb:5:in `repository' from (irb):1 -
Mark Bates September 18th, 2008 @ 09:07 PM
- → Tag changed from bug dm-core to bug dm-core
So I've taken Bernerd's suggestion and used properties(:hls).clear before I define my properties, and that seems to have helped, somewhat. Now, I'm getting new fun errors.
First, my model:
class Passenger include DataMapper::Resource storage_names[:hls] = "tbl_people" property :id, Serial property :first_name, String property :last_name, String property :notes, Text, :nullable => true, :lazy => false validates_present :first_name validates_present :last_name has 1, :passport has n, :tickets has n, :flights, :through => :tickets has n, :bookings, :through => :tickets repository(:hls) do properties(:hls).clear property :id, Serial property :full_name, LegacyName, :field => "name_ENC" property :eye_color, String, :nullable => true, :field => 'eyeColor', :lazy => :looks property :weight, Integer, :nullable => true, :lazy => :looks property :notes, Text, :nullable => true, :lazy => :all property :notes_2, Text, :nullable => true, :lazy => [:all, :extras] property :notes_3, Text, :nullable => true, :lazy => [:all, :extras] end endNow, the line I'm trying to execute:
p = Passenger.create(:first_name => 'Mark', :last_name => 'Bates')Note, I'm not calling anything in a repo block, so this is happening on my 'default' repo.
Now my error:
ArgumentError: Unknown property 'eye_color' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/resource.rb:106:in `attribute_get' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/model.rb:399:in `eye_color' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:118:in `send' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:118:in `validation_property_value' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/length_validator.rb:27:in `call' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/contextual_validators.rb:48:in `execute' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/contextual_validators.rb:46:in `each' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/contextual_validators.rb:46:in `execute' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:88:in `valid?' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:42:in `create' from (irb):3A different issue, but related, if I try to update a Passenger I got from a repository(:hls) block, update a parameter, and try to save it, nothing happens. It says the save was 'true', but nothing actually gets written back to the db:
repository(:hls) {puts @pass = Passport.first} DEBUG: [2008-09-18 22:01:54] SELECT `id`, `country_code`, `expdate`, `peopleid`, `country_code` FROM `tbl_pssptz` ORDER BY `id` LIMIT 1 #<Passport:0x24cfbec> => nil >> repository(:hls) {puts @passport = Passport.first} DEBUG: [2008-09-18 22:02:17] SELECT `id`, `country_code`, `expdate`, `peopleid`, `country_code` FROM `tbl_pssptz` ORDER BY `id` LIMIT 1 #<Passport:0x273f29c> => nil >> @passenger = @passport.passenger DEBUG: [2008-09-18 22:02:25] SELECT `id`, `name_ENC` FROM `tbl_people` WHERE (`id` IN (1)) ORDER BY `id` => #<Passenger id=1 full_name=#<Name:0x271599c @last_name="smith", @first_name="bob"> eye_color=<not loaded> weight=<not loaded> notes=<not loaded> notes_2=<not loaded> notes_3=<not loaded>> >> @passenger.eye_color DEBUG: [2008-09-18 22:02:35] SELECT `eyeColor`, `weight`, `id` FROM `tbl_people` WHERE (`id` IN (1)) ORDER BY `id` => "Hazel" >> @passenger.eye_color = 'Blue' => "Blue" >> @passenger.save => true >> repository(:hls) {puts Passenger.get(1).eye_color} DEBUG: [2008-09-18 22:03:17] SELECT `id`, `name_ENC` FROM `tbl_people` WHERE (`id` = 1) ORDER BY `id` LIMIT 1 DEBUG: [2008-09-18 22:03:17] SELECT `eyeColor`, `weight`, `id` FROM `tbl_people` WHERE (`id` = 1) ORDER BY `id` HazelAnd, just because I know you'd ask. If I wrap the whole thing in a repo block, I actually get a different type of error:
>> repository(:hls) do ?> p = Passenger.get(1) >> puts p.eye_color >> p.eye_color = 'Blue' >> p.save >> p = Passenger.get(1) >> puts p.eye_color >> end DEBUG: [2008-09-18 22:06:38] SELECT `id`, `name_ENC` FROM `tbl_people` WHERE (`id` = 1) ORDER BY `id` LIMIT 1 DEBUG: [2008-09-18 22:06:38] SELECT `eyeColor`, `weight`, `id` FROM `tbl_people` WHERE (`id` = 1) ORDER BY `id` Hazel ArgumentError: Unknown property 'first_name' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/resource.rb:106:in `attribute_get' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/model.rb:399:in `first_name' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:118:in `send' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:118:in `validation_property_value' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/length_validator.rb:27:in `call' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/contextual_validators.rb:48:in `execute' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/contextual_validators.rb:46:in `each' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations/contextual_validators.rb:46:in `execute' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:88:in `valid?' from /usr/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.6/lib/dm-validations.rb:61:in `save' from (irb):16 from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/support/kernel.rb:6:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core.rb:181:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/repository.rb:44:in `scope' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core.rb:181:in `repository' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/support/kernel.rb:6:in `repository'Any suggestions? This is the latest and greatest DM out there. Thanks.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
