mattgreen/nitron — pull request #11 by macfanatic (2012-06-21 20:45:08+00:00)
Title: Relation.except() support

This patch allows you to repurupose an existing relation (NSFetchRequest subclass). Needed this as I'm using Nitron with a NSFetchedResultsController and once instantiated, you cannot assign a new fetchRequest to the controller, but you can make any changes you need to the existing one.

This is driving a UITableView with little effort, and I can now use such as:

```ruby

# Calling this when a UISegmentedControl changes
def scope_results_by_status(term)
self.filter = term
request_controller.fetchRequest.except(:where).where("status = ?", term)
error = Pointer.new(:object)
NSLog "#{error[0]}, #{error[0].userInfo}" unless request_controller.performFetch(error)
end

# Datasource behind my UITableViewController
def request_controller
@request_controller ||= begin
c = NSFetchedResultsController.alloc.initWithFetchRequest(Consignment.order("created_at", ascending: false), managedObjectContext:App.delegate.managedObjectContext, sectionNameKeyPath:nil, cacheName:nil)
c.delegate = self
error = Pointer.new(:object)
unless c.performFetch(error)
NSLog "#{error[0]}, #{error[0].userInfo}"
abort
end
c
end
end
```