#529 ✓resolved
Juan Bernabó

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

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.

New-ticket Create new ticket

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

Attachments

Pages