# Chapter 4: Batch Updates question

**URL:** <https://forums.kodeco.com/t/chapter-4-batch-updates-question/45686>\
**Category:** Core Data by Tutorials\
**Created:** [August 8, 2018, 10:56pm UTC](https://forums.kodeco.com/t/chapter-4-batch-updates-question/45686 "2018-08-08T22:56:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xlsmearlx](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/xlsmearlx/32/105932_2.png) [@xlsmearlx](https://forums.kodeco.com/u/xlsmearlx)\
**Post date:** [August 8, 2018, 10:56pm UTC](https://forums.kodeco.com/t/chapter-4-batch-updates-question/45686/1 "2018-08-08T22:56:58Z")

</div>

Hi everyone!

I have a little question regarding the Batch updates example in chapter 4.

In the example the code updates all “Venues” to be my favorites like this:

> ```
> let batchUpdate = NSBatchUpdateRequest(entityName: "Venue")
> batchUpdate.propertiesToUpdate = [#keyPath(Venue.favorite) : true]
> batchUpdate.affectedStores = coreDataStack.managedContext.persistentStoreCoordinator?.persistentStores
> batchUpdate.resultType = .updatedObjectsCountResultType
> batchUpdate.predicate = NSPredicate(format: "%K == %@", #keyPath(Venue.priceInfo.priceCategory), "$$$")
> 
> do {
> let batchResult = try coreDataStack.managedContext.execute(batchUpdate) as! NSBatchUpdateResult
> print("Records updated \(batchResult.result!)")
> } catch let error as NSError {
> print("Could not update \(error), \(error.userInfo)")
> }
> 
> ```

But what if I just want to update the ones with the price category = “$” ?

I this predicate to the **NSBatchUpdateRequest** :

> batchUpdate.predicate = NSPredicate(format: “%K == %@”, #keyPath(Venue.priceInfo.priceCategory), “$$$”)

But the app crashes with this error:

> Bubble Tea Finder[77429:6687874] \*\*\* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘keypaths (joins) not supported in batch update statements’

Is there a way to update this Venues without fetching them in memory first?

Thanks!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [September 1, 2018, 1:48am UTC](https://forums.kodeco.com/t/chapter-4-batch-updates-question/45686/2 "2018-09-01T01:48:58Z")

</div>

@pietrorea Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![syedfa](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/syedfa/32/101500_2.png) [@syedfa](https://forums.kodeco.com/u/syedfa)\
**Post date:** [September 1, 2018, 3:56am UTC](https://forums.kodeco.com/t/chapter-4-batch-updates-question/45686/3 "2018-09-01T03:56:23Z")

</div>

@xlsmearlx Thanks very much for your question!

One of the advantages of using predicates is that you have the option of using multiple predicates together, so you don’t have to put all of your criteria into a single predicate. What I would suggest is use the existing predicate, and add another predicate to filter the results to include only those with $$$$. After combining the predicates, you should be able to pull the results you are looking for.

I hope this helps!

All the best!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [February 10, 2019, 11:19am UTC](https://forums.kodeco.com/t/chapter-4-batch-updates-question/45686/5 "2019-02-10T11:19:02Z")

</div>

Opened on February 10, 2019, 11:19am UTC


