小编Zbi*_*woń的帖子

CakePHP 3.x - hasMany通过关联 - 查找

假设我在CookBook中有完整的设置:http: //book.cakephp.org/3.0/en/orm/associations.html

class StudentsTable extends Table
{
    public function initialize(array $config)
    {
        $this->belongsToMany('Courses', [
            'through' => 'CourseMemberships',
        ]);
    }
}

class CoursesTable extends Table
{
    public function initialize(array $config)
    {
        $this->belongsToMany('Students', [
            'through' => 'CourseMemberships',
        ]);
    }
}

class CoursesMembershipsTable extends Table
{
    public function initialize(array $config)
    {
        $this->belongsTo('Students');
        $this->belongsTo('Courses');
    }
}

Student BelongsToMany Course
Course BelongsToMany Student

id | student_id | course_id | days_attended | grade
Run Code Online (Sandbox Code Playgroud)

我应该如何构建查询以查找给定学生的课程,他的成绩为=="A"?

$query = $this->Courses->find('all')
    ->contain(['CourseMemberships'])
    ->where(['CourseMemberships.student_id' => $student['id'], 'CourseMemberships.grade' => 'A']); …
Run Code Online (Sandbox Code Playgroud)

cakephp cakephp-3.0

4
推荐指数
1
解决办法
1万
查看次数

如何配置PhpStorm 10.x在CakePHP 3.x中运行单元测试?

有没有人有一个验证方法来配置PhpStorm 10.x在CakePHP 3.x中运行单元测试?

编辑:在@ndm的回答之后我修复了我的PhpStorm配置,将"phpunit.xml.dist"添加到PHPUnit> Test Runner:Checked Default配置文件.

现在我有不同的错误

/Applications/MAMP/bin/php/php5.6.10/bin/php /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/phpunit --configuration /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/phpunit.xml.dist /Applications/MAMP/htdocs/sites/my_app --teamcity

Testing started at 12:29 ...
PHP Warning: require(/Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/../vendor/autoload.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/bootstrap.php on line 3
PHP Fatal error:  require(): Failed opening required '/Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/../vendor/autoload.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.10/lib/php') in /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/bootstrap.php on line 3

Process finished with exit code 255
Run Code Online (Sandbox Code Playgroud)

在Run Config中,PHPUnit:Test Runner - > Test Scope - > Directory:

/Applications/MAMP/htdocs/sites/my_app/src
Run Code Online (Sandbox Code Playgroud)

cakephp phpstorm cakephp-3.1

3
推荐指数
1
解决办法
774
查看次数

标签 统计

cakephp ×2

cakephp-3.0 ×1

cakephp-3.1 ×1

phpstorm ×1