2017-04-06 69 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