如何在rails中干燥给定的查询代码

时间:2015-07-14 07:26:28

标签: ruby-on-rails ruby-on-rails-4

我已经给出了这段代码

public function validation()
{
        $this->validate(new MaxMinValidator(
            array(
                "field" => "Email",
                "min"   => 10,
                "max"   => 100
            )
        ));

        // This line:
        return $this->validationHasFailed() != true;
 }

获取@students。请指导我如何干这个查询。提前谢谢。

1 个答案:

答案 0 :(得分:0)

最好的方法:

Student
  .joins(student_classes: [:class])
  .where(classes: {employee_id: current_employee.id})