Repository and queries · Question 10 of 12
A search is to find all conferences whose title contains the search term $searchWord. Which constraint is correct?
1 answer is correct. Medium
Show answer
Answer
- B $query->like('title', '%' . $searchWord . '%')
Explanation
like() works like SQL LIKE: only the % wildcards before and after turn it into a substring search, without them it is an exact comparison. contains() checks whether a multi-valued relation (e.g. an ObjectStorage) contains a certain object, and equals() knows no wildcards. If the search term itself contains % or _, escape them first.