php - Cakephp 4: FIND_IN_SET not returning result
I have an array, , in my app that I implode to a delimited string:
$subs = implode(',', );
The string will look something like this: {-code-3}
. These values are stored in a field called {-code-4}
in my {-code-5}
table. Each {-code-6}
row has a unique {-code-4}
.
The following code builds menus and {-code-5} from a database:
$menus = $this->Menus->find('all', [
'order' => ['Menus.display_order ASC'],
'conditions' => $conditions,
'contain' => [
'{-code-10}' => [
'conditions' => [
'{-code-10}.status' => 1,
'{-code-9}("' . $subs . '", {-code-10}.{-code-4})'
],
]
]
]);
$this->set('menus', $menus);
It works fine until I add the {-code-9}
condition on {-code-10}
. When I do, I get no {-code-5} returned, just the main menus. Debug confirms that the string is formatted propery. Doesn't error out, I just get no resultset.
When I run the {-code-5} query in MySQL, it works.
set @prefixes = {-code-3};
SELECT `id`, `name` FROM `{-code-5}` WHERE `status` = 1 AND {-code-9}(`{-code-5}`.`{-code-4}`, @prefixes);
+----+Answer
Answer
-------+
| id | name |
+----+Answer
Answer
-------+
| 4 | Mission Lessons Module |
| 5 | MSR Module |
| 8 | Work Authorization Module |
+----+Answer
Answer
-------+
What am I missing?
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Solution:
Answer was to reverse the order of arguments in FIND_IN_SET.
Source