开发者

Why does the LIKE[c] in my subquery predicate not match this name?

开发者 https://www.devze.com 2023-01-04 05:32 出处:网络
I have two entities: Department and DepartmentInfo. Every Department has one or many DepartmentInfo Objects. Inside DepartmentInfo, there is an departmentName attribute.

I have two entities: Department and DepartmentInfo. Every Department has one or many DepartmentInfo Objects. Inside DepartmentInfo, there is an departmentName attribute.

I want to fetch all those Department objects which have a specific departmentName. So I make an NSFetchRequest for the Department entity, and use this fetch request:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(departmentName, $s, $s.departmentName LIKE[c] %@).@count > 0", @"Marketing"];

It works, BUT: The LIKE[c] doesn't! I must match against the exact department name. If I do this, I will get no match:

NSPredicate 开发者_如何学C*predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(departmentName, $s, $s.departmentName LIKE[c] %@).@count > 0", @"Mar"];

What could be wrong here?


Since Jason Coco didn't post this as answer, I do it:

Use @"Mar*" and you will match


The use of SUBQUERY here is unnecessary. You can achieve the same results using:

ANY departmentInfo.departmentName LIKE[c] 'Mar*'

Execute that against an array of Department objects and it'll work.

0

精彩评论

暂无评论...
验证码 换一张
取 消