Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在rails控制台中从多对一关系中选择联接表?_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 如何在rails控制台中从多对一关系中选择联接表?

Ruby on rails 如何在rails控制台中从多对一关系中选择联接表?,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有这样的关系: Appointment belongs to task Task has many appointments 我在task中有一个名为的属性,它是布尔值 我的问题是,我希望能够选择任务所属的所有约会类型为每小时工资 我正在使用以下语法,但它不起作用: User.first.appointments.joins(:task).where(is_pay_per_hour: true) Appointment.joins(:task).where(is_pay_per_hour:

我有这样的关系:

Appointment belongs to task
Task has many appointments
我在
task
中有一个名为
的属性,它是
布尔值

我的问题是,我希望能够选择
任务所属的所有
约会
类型为
每小时工资

我正在使用以下语法,但它不起作用:

User.first.appointments.joins(:task).where(is_pay_per_hour: true)
Appointment.joins(:task).where(is_pay_per_hour: true)

请帮助,

您必须使用
where
方法指定此项。比如说

Appointment.joins(:task).where(tasks: {is_pay_per_hour:true}).all

请提供更多信息。

如果表名为
tasks
那么where子句应该是
where(tasks:{is\u pay\u per\u hour:true})
您就快到了:使用
where(tasks:{is\u pay\u per\u hour:true})
而不是让它工作了。谢谢你@吉吉先生