
Adding derived classes of has n association fails
Reported by Juan Bernabó | August 17th, 2008 @ 02:25 AM
Given:
class Party
include DataMapper::Resource
property :id, Integer, :key => true
property :name, String
has n, :party_roles
end
class Person < Party
end
class PartyRole
include DataMapper::Resource
property :id, Integer, :key => true
property :name, String
belongs :party
end
class PersonRole < PartyRole
end
When:
def test_that_is_saving
DataMapper.setup(:default, 'mysql://root:xxxx@localhost/learning_do')
DataObjects::Mysql.logger = DataMapper::Logger.new(STDOUT, 0)
DataMapper.auto_migrate!
juan = Person.new(:name => 'Juan')
buyer = PersonRole.new(:name => 'Buyer') # This don't work (cannot find party_id property)
# buyer = PartyRole.new(:name => 'Buyer') # This works (it finds party_id property)
juan.party_roles << buyer
juan.save
end
Then:
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ DROP TABLE IF EXISTS `party_roles`
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ SELECT COUNT(*) FROM `information_schema`.`columns` WHERE `table_schema` = 'learning_do' AND `table_name` = 'party_roles'
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ SHOW VARIABLES WHERE `variable_name` = 'character_set_connection'
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ SHOW VARIABLES WHERE `variable_name` = 'collation_connection'
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ CREATE TABLE `party_roles` (`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(50), `party_id` INT(11), PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ DROP TABLE IF EXISTS `parties`
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ SELECT COUNT(*) FROM `information_schema`.`columns` WHERE `table_schema` = 'learning_do' AND `table_name` = 'parties'
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ CREATE TABLE `parties` (`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(50), `type` VARCHAR(50) NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
Sun, 17 Aug 2008 07:18:43 GMT ~ debug ~ SELECT `id`, `name`, `party_id` FROM `party_roles` WHERE `party_id` IN (NULL) ORDER BY `id`
E
Finished in 0.086743 seconds.
1) Error:
test_that_is_saving(PartiesTest):
ArgumentError: Unknown property 'party_id'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/resource.rb:315:in `attribute_loaded?'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:267:in `add_default_association_values'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:266:in `each'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:266:in `add_default_association_values'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:278:in `relate_resource'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.3/lib/dm-core/associations/one_to_many.rb:96:in `<<'
test/test_parties.rb:17:in `test_that_is_saving'
Comments and changes to this ticket
-
Dan Kubb (dkubb) January 8th, 2009 @ 05:08 AM
- State changed from new to accepted
- Assigned user changed from Sam Smoot to Dan Kubb (dkubb)
-
Jonathan Stott (namelessjon) February 22nd, 2009 @ 10:44 AM
- Tag changed from belongs_to, bug, has_many to belongs_to, bug, has_many, one_file_test
- State changed from accepted to resolved
This is fixed in 0.10.0, with the Juan saved successfully. (see attached one file test)
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 »