Skip to content

ManyToMany association can't use IN / OR criteria  #6173

@shaunxq

Description

@shaunxq
class Member
{
   ...
    /**
     * @ManyToMany(targetEntity="Message")
     * @JoinTable(name="t_member_message",
     *        joinColumns={@JoinColumn(name="member_id", referencedColumnName="id")},
     *        inverseJoinColumns={@JoinColumn(name="message_id", referencedColumnName="id")}
     *      )
     */
    protected $messages;
...
    publicpublic function getMessages()
    {
        $criteria = Criteria::create()->where(Criteria::expr()->in("entity_type", ['system', 'test']));
        return $this->messages->matching($criteria);
    }
}
Notice: Array to string conversion in doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php on line 91

SQL becomes

   SELECT .... WHERE t.member_id = '111' AND te.entity_type = **'Array'**

Criteria method orWhere() doesn't work in many-to-many association as well

$criteria = Criteria::create()->where(Criteria::expr()->eq("entity_type", 'system'))
                                          ->orWhere(Criteria::expr()->eq("entity_type", 'test'));
        return $this->messages->matching($criteria);

SQL becomes

SELECT .... WHERE t.member_id = '111' AND te.entity_type = 'system' **AND** te.entity_type = 'test'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions