
HABTM can't handle camelcase class names
Reported by Mike Summers | August 27th, 2008 @ 09:27 AM
HABTM breaks when one or more of the classes involved has a camelcase classname. Code:
class EnergySomething
include DataMapper::Resource
property :id, Serial
has n, :users, :through => Resource
end
class User
include DataMapper::Resource
property :id, Serial
has n, :energySomethings, :through => Resource
end
!DataMapper.auto_migrate!
user1 = User.create
user2 = User.create
er1 = EnergySomething.create
er2 = EnergySomething.create
er2.users << user2
er2.save
user1.energySomethings << er1 # Exception thrown here
user1.save
Stack trace:
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/query.rb:372:in `normalize_links': +options[:links]+ entry nil not supported (ArgumentError)
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/query.rb:189:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/model.rb:358:in `new'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/model.rb:358:in `scoped_query'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/model.rb:216:in `all'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/relationship_chain.rb:26:in `send'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/relationship_chain.rb:26:in `get_children'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/repository.rb:44:in `scope'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core.rb:185:in `repository'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/support/kernel.rb:5:in `repository'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/relationship.rb:167:in `with_repository'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/relationship_chain.rb:25:in `get_children'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:242:in `children'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:300:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:93:in `<<'
from /home/mike/NetBeansProjects/FB/test/dmRepositoryTest.rb:37
SQL trace:
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ DROP TABLE IF EXISTS `energy_somethings`
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ SELECT COUNT(*) FROM `information_schema`.`columns` WHERE `table_schema` = 'test' AND `table_name` = 'energy_somethings'
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ SHOW VARIABLES WHERE `variable_name` = 'character_set_connection'
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ SHOW VARIABLES WHERE `variable_name` = 'collation_connection'
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ CREATE TABLE `energy_somethings` (`id` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ DROP TABLE IF EXISTS `users`
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ SELECT COUNT(*) FROM `information_schema`.`columns` WHERE `table_schema` = 'test' AND `table_name` = 'users'
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ CREATE TABLE `users` (`id` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ DROP TABLE IF EXISTS `energy_somethings_users`
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ SELECT COUNT(*) FROM `information_schema`.`columns` WHERE `table_schema` = 'test' AND `table_name` = 'energy_somethings_users'
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ CREATE TABLE `energy_somethings_users` (`energy_something_id` INT(11) NOT NULL, `user_id` INT(11) NOT NULL, PRIMARY KEY(`energy_something_id`, `user_id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ INSERT INTO `users` () VALUES ()
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ INSERT INTO `users` () VALUES ()
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ INSERT INTO `energy_somethings` () VALUES ()
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ INSERT INTO `energy_somethings` () VALUES ()
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ SELECT `users`.`id` FROM `users` INNER JOIN `energy_somethings_users` ON `users`.`id` = `energy_somethings_users`.`user_id` WHERE `energy_somethings_users`.`energy_something_id` = 2 GROUP BY `users`.`id` ORDER BY `users`.`id`
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ SELECT `energy_something_id`, `user_id` FROM `energy_somethings_users` WHERE `energy_something_id` IN (2) ORDER BY `energy_something_id`, `user_id`
Wed, 27 Aug 2008 14:19:16 GMT ~ debug ~ INSERT INTO `energy_somethings_users` (`energy_something_id`, `user_id`) VALUES (2, 2)
Comments and changes to this ticket
-
Dan Kubb (dkubb) December 12th, 2008 @ 04:37 PM
- Assigned user cleared.
- State changed from new to not-applicable
Mike, I think it's reasonable for DM to enforce the naming convention on the association names. However, if you would like to supply a patch that does not overly complicate the association code I would accept and apply it.
Marking this as not applicable for now.
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 »
People watching this ticket
- Nobody is watching this ticket.