Try this:

$tasks = $this->Task->find('all', array(
  'conditions' => array(
    'or' => array(
      array('user_id' => $user_id),
      array('alternate_id' => $user_id, 'user_id' => '<> ' . $user_id)
    ),
    'duedate' => date('Y-m-d')
  ),
  'order' => 'duedate ASC'
));

On May 16, 2:53 pm, Pierre MARCOURT <[EMAIL PROTECTED]> wrote:
> Here are the requests I am doing :
>
> $tab1 = $this->Task->findAll('user_id = ' . $user_id . ' AND duedate =
> "' . date('Y-m-d') . '"', null, 'duedate ASC');
> $tab2 = $this->Task->findAll('alternate_id = ' . $user_id . ' AND
> user_id != '.$user_id.' AND duedate = "' . date('Y-m-d') . '"', null,
> 'duedate ASC');
> $tasks = array_merge($tab1, $tab2);
> $this->set('tasks', $tasks);
>
> I don't like that way, because I am using twice /findAll()/ on the same
> table and for only one result at the end.
> That's why I was wondering if there is a way to do it better.
>
> I think that your example is better than mine because you are doing a
> simple query ($tmp) to get the ids (this query should not take too long)
> and then the /findAll()/ query.
> I don't like my way because, by using twice /findAll()/, my requests
> could take too long for a lot of rows... And I don't see how to rewrite
> it without using UNION because there is the condition user_id !=
> '.$user_id.' in the 2nd one which is the contrary of 'user_id = ' .
> $user_id . ' in the first one...
>
> Anyway, thanks for you help !
>
>
>
> grigri wrote:
> > In a word, no.
>
> > In a UNION, MySQL does not return any table information with each
> > column [since it can't, because a union can be from different tables],
> > and cakephp's dbo_mysql class relies on this information to map the
> > result rows to the originating model (think left joins).
>
> > What exactly is the query you're trying to produce? There must be a
> > way to rewrite it to not use a union (which are not usually that
> > efficient anyway).
>
> > If the union query you're creating is from the same table, you could
> > always perform the union as a query(), but only return the row ids,
> > then use Set::extract() on the result to get the ids into a flattened
> > list, then call findAll with the id list:
>
> > $tmp = $this->query('SELECT Product.id FROM [complicated sql] UNION
> > SELECT Product.id FROM [complicated sql]');
> > $ids = Set::extract($tmp, '{n}.0.id');
> > $products = $this->findAll(array('Product.id' => $ids));
>
> > hth
> > grigri
>
> > On May 16, 2:17 pm, Pierre MARCOURT <[EMAIL PROTECTED]> wrote:
>
> >> Hi,
>
> >> I would like to make a MySQL request with an UNION but I can't find out
> >> a way to do it by using CakePHP methods.
> >> I looked at Google but it seems that the only way to do it is to make a
> >> custom request by using /query()/.
> >> But I don't want to do it that way because I need the recursive option
> >> that we can have with /find()/ or /findAll()/.
> >> So, to make it works, I am doing 2 different requests (by using
> >> /findAll()/) and I merge the 2 results in a array().
> >> To be honest, I don't like my idea at all.
>
> >> I would like to know if there is another way to do it better ?
>
> >> Thanks.
>
> >> --
> >>  *Pierre MARCOURT*
>
> >> *IT Department*
> >>         *CableOrganizer.com*
> >> 5610 NW 12th Ave, suite 214
> >> Fort Lauderdale, FL 33304
>
> >>         Phone: 954-861-6310
> >> Fax: 954-861-2001
>
> --
>  *Pierre MARCOURT*
>
> *IT Department*
>         *CableOrganizer.com*
> 5610 NW 12th Ave, suite 214
> Fort Lauderdale, FL 33304
>
>         Phone: 954-861-6310
> Fax: 954-861-2001
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to