Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

has_many with conditions in hash format generates invalid syntax

#1461

Environment: Rails 2.2.2 and Postgres database.

A simple has_many relationship works in rails 2.1.2 but fails due to invalid sql syntax in 2.2.2.

The failing has_many: has_many :keys, :foreign_key => "keyboard_id", :conditions => {:position => 'pressed'}, :dependent => :nullify # fails

This has_many does not generate the with invalid syntax error: has_many :keys, :foreign_key => "keyboard_id", :conditions => "position = 'pressed'", :dependent => :nullify # works

Below is the output. Attached is a very simple project with 2 models. The output.log is in the root of the tgz.

=> Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails 2.2.2 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Starting Mongrel listening at 0.0.0.0:3000 Starting Rails with production environment... Exiting /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations.rb:1476:in configure_dependency_for_has_many': (eval):9:inconfigure_dependency_for_has_many': compile error (SyntaxError) (eval):7: syntax error, unexpected tIDENTIFIER, expecting ')'

                  "(keyboard_id = #{record.quoted_id}) AND ("keyboards"."position" = E'pressed')")
                                                                      ^

(eval):7: syntax error, unexpected tIDENTIFIER, expecting kEND

                  "(keyboard_id = #{record.quoted_id}) AND ("keyboards"."position" = E'pressed')")
                                                                                 ^

(eval):7: syntax error, unexpected ')', expecting kEND from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations.rb:768:in has_many'

from /home/jrafaniello/git_src/test_project/app/models/keyboard.rb:2
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:262:in `require_or_load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:221:in `depend_on'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:133:in `require_dependency'
 ... 35 levels...
from /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3

Reported by Joe Rafaniello · November 24th, 2008 @ 09:15 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Repository
    Repository
    • State changed from new to resolved

    (from [b17b9371c6a26484eb1984d45acffcdcd91b1ae1]) Fix configure_dependency_for_has_many not quoting conditions properly [#1461 state:resolved] http://github.com/rails/rails/co...

    December 21st, 2008 @ 04:07 PM