I am using 1.1 and your last code works just fine !!!
Thank you very much, it is just what I needed !


grigri wrote:
> Very odd indeed. Works fine for me... what version are you using? This
> was on a bleeding edge 1.2 but it works on older versions too.
>
> If you're on 1.1, try this:
>
> $tasks = $this->Task->findAll(
>   array(
>     'or' => array(
>       array('user_id' => $user_id),
>       array('alternate_id' => $user_id, 'user_id' => '<> ' . $user_id)
>     ),
>     'duedate' => date('Y-m-d')
>   ),
>   null,
>   'duedate ASC'
> ));
>
> On May 16, 3:23 pm, Pierre MARCOURT <[EMAIL PROTECTED]> wrote:
>   
>> It does not work...
>> I have a SQL Error.
>> Here it is :
>>
>> *Notice*: Undefined offset: 0 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1388*
>> *Notice*: Undefined offset: 0 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1390*
>> *Notice*: Undefined offset: 0 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1393*
>> *Notice*: Undefined offset: 0 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1397*
>> *Notice*: Undefined offset: 0 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1400*
>> *Notice*: Undefined offset: 1 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1390*
>> *Notice*: Undefined offset: 1 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1393*
>> *Notice*: Undefined offset: 1 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1397*
>> *Notice*: Undefined offset: 1 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1400*
>>
>> *Notice*: Array to string conversion in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *1149*
>> *Query:* SELECT Array, duedate ASC, `Task`. FROM `tasks` AS `Task` LEFT
>> JOIN `users` AS `User` ON (`Task`.`user_id` = `User`.`id`) LEFT JOIN
>> `users` AS `Assigned` ON (`Task`.`assigned_id` = `Assigned`.`id`) LEFT
>> JOIN `marks` AS `Mark` ON (`Task`.`mark_user_id` = `Mark`.`mark_id`)
>> LEFT JOIN `progresses` AS `Progress` ON (`Task`.`progress_id` =
>> `Progress`.`progress_id`) LEFT JOIN `priorities` AS `Priority` ON
>> (`Task`.`priority_id` = `Priority`.`priority_id`) WHERE all LIMIT 1
>> *Warning*: *SQL Error:* 1064: You have an error in your SQL syntax;
>> check the manual that corresponds to your MySQL server version for the
>> right syntax to use near 'ASC, `Task`. FROM `tasks` AS `Task` LEFT JOIN
>> `users` AS `User` ON (`Task`.`user' at line 1 in
>> *Z:\dev\frameworks\cake\cake\libs\model\datasources\dbo_source.php* on
>> line *440*
>>
>> I try by changing your code regarding to the error but I still get a SQL
>> Error...
>>
>>
>>
>> grigri wrote:
>>     
>>> 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
>>>>         
>> --
>>  *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