2017-04-06 68 views
0

我無法將關聯添加到某些現有代碼。ActiveRecord查詢,添加內部連接,但獲取語法錯誤

這工作:

PropertySpa.joins(:spa_results, :country)

和這個作品:

PropertySpa.joins(:spa_results => [:comp_status])

但結合這一切讓我想不工作是什麼:

PropertySpa.joins(:spa_results => [:comp_status], :country)

給我的錯誤:

SyntaxError: (irb):18: syntax error, unexpected ')', expecting => from /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in start' from /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in start' from /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console ...

感謝您的任何幫助。

+0

你可以試試'PropertySpa.joins([{:spa_results => [:comp_status]},:country)]'? –

回答

0

試試這個方法。

PropertySpa.joins(:country, :spa_results => [:comp_status]) 

大多數方法將被寫入預期隱含的哈希值是一個方法的最後一個參數。

+0

謝謝,我認爲就是這樣。 – bethesdaboys