#471 ✓resolved
Anthony Williams

74dc532: Getting a many_to_one parent raises an exception.

Reported by Anthony Williams | July 19th, 2008 @ 11:30 AM

74dc532 appears to change Relationship#get_parent such that using an association on an unsaved record, having set the association by the ID, rather than the associated record, results in a raised exception.

undefined method `reject' for nil:NilClass
dm/dm-core/lib/dm-core/associations/relationship.rb:139:in `get_parent'
dm/dm-core/lib/dm-core/repository.rb:44:in `scope'
dm/dm-core/lib/dm-core.rb:185:in `repository'
dm/dm-core/lib/dm-core/support/kernel.rb:5:in `repository'
dm/dm-core/lib/dm-core/associations/relationship.rb:163:in `with_repository'
dm/dm-core/lib/dm-core/associations/relationship.rb:128:in `get_parent'
dm/dm-core/lib/dm-core/associations/many_to_one.rb:92:in `parent'
dm/dm-core/lib/dm-core/associations/many_to_one.rb:96:in `method_missing'
dm/dm-core/lib/dm-core/associations/many_to_one.rb:17:in `machine'
dm/dm-core/spec/integration/association_spec.rb:348

Attached a failing spec.

Unfortunately I don't know the relationship code anywhere near well enough to attempt fixing this myself. In a local branch I've reverted 74dc532 which results in the spec passing (aside from the pending block). Since there were no specs provided with 74dc532 (sigh), I haven't a clue whether a revert is a good idea.

Thanks, Anthony.

Update: It turns out that removing the splat operator on relationship.rb L139 is enough to fix this without resulting in any other failing specs. Though, again, without specs for this commit I don't want to go removing it myself, only to break something else.

Comments and changes to this ticket

  • Anthony Williams

    Anthony Williams July 19th, 2008 @ 01:30 PM

    A quick update... removing the splat doesn't solve the problem after all. The specs are fine using the default sqlite3 adapter, but not mysql:

    MysqlError in 'DataMapper::Associations many to one associations should fetch the association when it has been set using the key'
    dm/dm-core/lib/dm-core/adapters/data_objects_adapter.rb:45:in `execute_reader'
    dm/dm-core/lib/dm-core/adapters/data_objects_adapter.rb:45:in `read_many'
    dm/dm-core/lib/dm-core/adapters/data_objects_adapter.rb:168:in `with_connection'
    dm/dm-core/lib/dm-core/adapters/data_objects_adapter.rb:40:in `read_many'
    dm/dm-core/lib/dm-core/associations/relationship.rb:147:in `send'
    dm/dm-core/lib/dm-core/associations/relationship.rb:147:in `get_parent'
    dm/dm-core/lib/dm-core/repository.rb:44:in `scope'
    dm/dm-core/lib/dm-core.rb:185:in `repository'
    dm/dm-core/lib/dm-core/support/kernel.rb:5:in `repository'
    dm/dm-core/lib/dm-core/associations/relationship.rb:163:in `with_repository'
    dm/dm-core/lib/dm-core/associations/relationship.rb:128:in `get_parent'
    dm/dm-core/lib/dm-core/associations/many_to_one.rb:92:in `parent'
    dm/dm-core/lib/dm-core/associations/many_to_one.rb:96:in `method_missing'
    dm/dm-core/lib/dm-core/associations/many_to_one.rb:17:in `machine'
    dm/dm-core/spec/integration/association_spec.rb:348:
    

    I don't have PostgreSQL installed, so I'm not sure what the situation is there.

    It would appear that data_objects_adapter.rb:45 splats the bind_values, which, being an empty array, ends up being nil.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 2nd, 2008 @ 03:33 AM

    • State changed from “new” to “resolved”
    • Assigned user changed from “Sam Smoot” to “Dan Kubb (dkubb)”

    I can confirm this is resolved in dkubb/dm-core, attaching a stand-alone test script that demonstrates the solution.

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