#483 ✓resolved
Richard Grundy (RichGuk)

Problem using conditions within an association

Reported by Richard Grundy (RichGuk) | July 25th, 2008 @ 01:46 PM

When doing

course.course_dates.all(:conditions => ['MONTH(start_date) = ? AND YEAR(start_date) = ?', 8, 2008])

The following error occurs:

NoMethodError: undefined method `name' for MONTH(start_date) = ? AND YEAR(start_date) = ?

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/relationship.rb:106:in `get_children'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/relationship.rb:105:in `map!'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/relationship.rb:105:in `get_children'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/relationship.rb:101:in `each'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/relationship.rb:101:in `get_children'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/repository.rb:44:in `scope'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core.rb:185:in `repository'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/support/kernel.rb:5:in `repository'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/relationship.rb:167:in `with_repository'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/relationship.rb:80:in `get_children'

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.4/lib/dm-core/associations/one_to_many.rb:79:in `all'

The problem does not happen when doing the following:

CourseDate.all(:conditions => ['MONTH(start_date) = ? AND YEAR(start_date) = ?', 8, 2008])

course.course_dates.first(:conditions => ['MONTH(start_date) = ? AND YEAR(start_date) = ?', 8, 2008])

Line 6 of dm-core/associations/relationship.rb contains

if child_key.has_property?(property.name)

which when commented out stopped the error.

I think that line was added in this commit: http://github.com/sam/dm-core/co...

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

Tags

Pages