Querybuilder:错误:字符串的预期结束,得到了'('

时间:2017-07-13 14:04:42

标签: php symfony doctrine-orm

这是查询:

public function getTeachersBySchool(School $school)
    {  

        $qb2 = $this->getEntityManager()->createQueryBuilder('UserGroup ug')
                ->select('ug.members')
                ->where('ug.school = :school')
                ->andWhere('ug.name = "teachers"')
                ->setParameter('school', $school)    
                ;

        $qb = $this->getEntityManager()->createQueryBuilder('Project\UserBundle\Entity\User u');

        $query = $qb
                ->select('Project\UserBundle\Entity\User')
                ->where($qb->expr()->in('Project\UserBundle\Entity\User', $qb2->getDQL()))   
            ;

        return $query;
    }

我无法理解为什么会出现此错误,尤其是所提出的SQL查询似乎是正确的:

SELECT Project\UserBundle\Entity\User WHERE Project\UserBundle\Entity\User IN(SELECT ug.members WHERE ug.school = :school AND ug.name = "teachers") 

编辑:我不认为问题来自andWhere('ug.name = "teachers"'),因为即使删除此行,错误仍然相同。

3 个答案:

答案 0 :(得分:0)

尝试

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_below="@+id/rlTop"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:padding="@dimen/activity_horizontal_margin">

    <TextView
        android:id="@+id/tvHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_horizontal_margin"
        android:padding="@dimen/edit_text_padding"
        android:text="@string/type_data_to_access_central"
        android:textColor="@color/mediumGray" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/inputEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/TextInputStyle"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        app:passwordToggleEnabled="false">

        <EditText // -- This is line 29 --
            android:id="@+id/etEmail"
            style="@style/FormEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/your_email"
            android:inputType="textEmailAddress" />
    </android.support.design.widget.TextInputLayout>

答案 1 :(得分:0)

试试这个:

        $qb2 = $this->getEntityManager()->createQueryBuilder('UserGroup ug')
            ->select('ug.members')
            ->where('ug.school = :school')
            ->andWhere('ug.name = :teachers')
            ->setParameters([
               'school' => $school,
               'teachers' => "teachers"
            ]);

答案 2 :(得分:0)

试试这个:

    $qb2 = $this->getEntityManager()->createQueryBuilder()
            ->select('ug.members')
            ->from(UserGroup::class, 'ug')
            ->where('ug.school = :school')
            ->andWhere('ug.name = "teachers"')
            ->setParameter('school', $school);