views:

18

answers:

1

Hi,

I try to translate this query into Criteria (with Propel), but without success.

Can you help me please ?

SELECT DISTINCT (email)
FROM user, travail
WHERE travail.id_user = user.id_user
AND id_site = "1"
AND `droits` = "1"

This my Criteria query :

  $c = new Criteria();
  $c->add(self::DROITS, 1, Criteria::EQUAL);
  $c->add(TravailPeer::ID_SITE, 1, CRITERIA::EQUAL);
  $c->setDistinct(self::EMAIL);
A: 

How about this:

$c = new Criteria();
$c->add(UserPeer::DROITS, 1);
$c->addJoin(UserPeer::ID_USER, TravailPeer::ID_USER);
$c->add(TravailPeer::ID_SITE, 1);
$c->clearSelectColumns();
$c->addSelectColumn(UserPeer::EMAIL);
$c->setDistinct();

$rs = UserPeer::doSelectRS($c);
Raise
I obtain an error : Error populating User object [wrapped: Invalid resultset column: 2]
bahamut100
D'oh, last line should read: `$rs = UserPeer::doSelectRS($c);`
Raise
It works, thanks :)
bahamut100