Ticket #614 (closed defect: invalid)

Opened 2 years ago

Last modified 2 years ago

Hydration issues when using IN ()

Reported by: jwage Owned by: somebody
Priority: minor Milestone: 2.0.0 (OLD)
Component: Other Version:
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description

Doesn't work

$groupIds = array(1, 2, 3);
$query = new Doctrine_Query();
$query->from('Deal d, d.Groups g');
$query->where('g.id IN (?)', $groupIds);

Does work

$groupIds = array(1, 2, 3);
$query = new Doctrine_Query();
$query->from('Deal d, d.Groups g');

foreach ($groupIds as $group_id)
{
  $where .= 'g.id = ' . $group_id . ' or ';
}

$where = substr($where, 0, strlen($where) - 4);
$query->where($where);

The example that doesn't work only returns one Deal record no matter how many are actually returned. When I do $query->getSql() and feed the sql right to the database, more than 1 row is returned. I will try and produce this in a test case and update here.

Change History

Changed 2 years ago by romanb

  • status changed from new to closed
  • resolution set to invalid

This is no bug. You have 2 options:

1) Write as many '?' as there are parameters yourself

or

2) Use whereIn() which does it for you. See the link below for an example  http://doctrine.pengus.net/index.php/documentation/manual?one-page#working-with-objects:dealing-with-relations:deleting-related-records

Note: See TracTickets for help on using tickets.