README.md in cdq-1.0.2 vs README.md in cdq-1.0.3

- old
+ new

@@ -115,10 +115,29 @@ end ``` Ruby-xcdm translates these files straight into the XML format that Xcode uses for datamodels. +### Boolean Values + +Since CoreData stores boolean values as an `NSNumber`, cdq provides helper +methods to allow you to get the boolean value of the property. Take the `Article` +model from above with the `boolean`:`published`. If you call `published` directly +you'll get the `NSNumber` `0` or `1`. If you call `published?` you'll get a +boolean `true` or `false` + +```ruby +article_1 = Article.create(published: true) +article_2 = Article.create(published: false) + +article_1.published # => 1 +article_2.published # => 0 + +article_1.published? # => true +article_2.published? # => false +``` + ## Context Management Managing NSManagedObjectContext objects in Core Data can be tricky, especially if you are trying to take advantage of nested contexts for better threading behavior. One of the best parts of CDQ is that it handles contexts for you @@ -189,10 +208,12 @@ author = Author.first author.name = "Ursula K. Le Guin" cdq.save ``` +**NOTE** Custom class methods will have to `include CDQ` in order to have access to the `cdq` object. If you're calling `cdq` from a class method, you also have to `extend CDQ`. + ### Deleting ```ruby author = Author.first author.destroy cdq.save @@ -247,17 +268,28 @@ ```ruby Author.where(:name).contains("Emily").and(cdq(:pub_count).gt(100).or.lt(10)) ``` +### Calculations + +```ruby + Author.sum(:fee) + Author.average(:fee) + Author.min(:fee) + Author.max(:fee) + Author.where(:name).eq("Emily").sum(:fee) +``` + ### Fetching Like ActiveRecord, CDQ will not run a fetch until you actually request specific objects. There are several methods for getting at the data: * `array` * `first` + * `last` * `each` * `[]` * `map` * Anything else in `Enumerable` @@ -353,5 +385,14 @@ * There is no facility for custom migrations yet * There are no explicit validations (but you can define them on your data model) * Lifecycle Callbacks or Observers +## Tips + +If you need, you could watch SQL statements by setting the following launch argument through `args` environment variable: + +``` +$ rake args='-com.apple.CoreData.SQLDebug 3' +``` + +`com.apple.CoreData.SQLDebug` takes a value between 1 and 3; the higher the value, the more verbose the output.