Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shaunxq opened this issue Dec 15, 2016 · 1 comment
Open

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

shaunxq opened this issue Dec 15, 2016 · 1 comment

Comments

@shaunxq
Copy link

shaunxq commented Dec 15, 2016

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'
@lcobucci
Copy link
Member

@shaunxq thanks for pointing this out.
Could you please create a failing test case for this? You can find examples here: https://github.com/doctrine/doctrine2/tree/6e6be3fdd92728b26a79576f7f91abe4080e54ff/tests/Doctrine/Tests/ORM/Functional/Ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants