README.md in arel-helpers-2.10.0 vs README.md in arel-helpers-2.11.0

- old
+ new

@@ -185,9 +185,35 @@ .with_comments_by(['camertron', 'catwithtail']) .with_title_matching("arel rocks") .since_yesterday ``` +#### Conditional reflections + +If you have parts of a query that should only be added under certain conditions you can return `reflect(query)` from your method. E.g: + +```ruby + def with_comments_by(usernames) + if usernames + reflect( + query.where(post[:title].matches("%#{title}%")) + ) + else + reflect(query) + end + end +``` + +This can become repetitive, and as an alternative you can choose to prepend `not_nil` to your method definition: + +```ruby + class PostQueryBuilder < ArelHelpers::QueryBuilder + not_nil def with_comments_by(usernames) + reflect(query.where(post[:title].matches("%#{title}%"))) if usernames + end + end +``` + ## Requirements Requires ActiveRecord >= 3.1.0, < 6, tested against Ruby 2.2.4. Depends on SQLite for testing purposes. ## Running Tests