2

i am using this code snippet for apply condition to fetch data from database

array( 'Account.type_id' => $account_type_id_ids );

where $account_ids for example is {3,10}. i am passing through

Array
(
    [0] => 3
    [1] => 10
)

but in accounts table there is multiple rows with these ID's

like :

id    | type_id
1     |    2
2     |    3
3     |    2
4     |    3
5     |    10

so this must be fetch rows {2,4,5} but when i print_r this data i got a list of only {2,5} i want to fetch all those three

4
  • What is the SQL query being generated by Cake for your find? Sep 3, 2015 at 11:58
  • please share your cakephp query code Sep 3, 2015 at 12:12
  • it is very big , but i can show a snippet that you want. WHERE Account.type_id IN (3, 10) Sep 3, 2015 at 12:14
  • 1
    To me this sounds as if you are using some kind of grouping.
    – ndm
    Sep 3, 2015 at 13:35

1 Answer 1

-1

please try this one if you are using cakephp 2.6

array( 'Account.type_id IN' => "'.$account_type_id_ids.'" );
2
  • In Cake you should really be using an array for the values of the IN query like array( 'Account.type_id IN' => [3, 10]); rather than attempting to build the condition yourself. Sep 3, 2015 at 13:24
  • 1
    -1 How can this be a solution anyways? This will yield an "array to string conversion" notice, and end up as invalid SQL like Account.type_id IN '\'.Array.\''.
    – ndm
    Sep 3, 2015 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.